View Full Version : how get the response of the server ?

19 May 2007, 12:56 PM
Hi everyone. I am an engineer student, and I have been looking on the forum for 2 weeks before asking, but I have not found... (so mush posts on this forum !)
Here is my problem :I wish to get the response of the server, and my tries are not successful at all :s.
I have an ext form, which call a php file for inserting data in a Mysql database. I would like to get the response of the server in order to display it in a small popup in aim to make the user aware of the good progress of the action he validates.
Here is my php code :
$sql="INSERT INTO 'table' VALUES (1, '".$_POST['libelle']."'))";


19 May 2007, 1:57 PM
everything looks good for the first glance....:-?

Put breakpoint to this line:

var decodedArray = Ext.util.JSON.decode( o.responseText);
to see if execution stops there. It should. Then explore with firebug the arguments of the event handler (form, acion, o).

It could give you an information what data from server you can find where.

19 May 2007, 2:02 PM

one more thing. There should be no extra spaces in json string.

If you have php 5.2.0 or later use this:

$o = new stdClass;
$o->success = true;
$o->xxxx = yyyy;
echo json_encode($o)

19 May 2007, 6:33 PM
In the callback function, the param action.result is the return JSON object.

So, u may want to use something like this:
success:function(form, action)
var id = action.result.id;
var monErreur = action.result.monErreur;
Ext.MessageBox.alert('Status', 'Changes saved successfully.');

BTW:how can i use ajax directly in Ext? use Ext.util.ajax? any example?

19 May 2007, 6:38 PM
Hi finian,

thanks for helping others.

BTW:how can i use ajax directly in Ext? use Ext.util.ajax? any example?I guess it would be better to post this question in a separate thread you're more likely then to get answer fast.

I personally don't know; never tried.

19 May 2007, 6:45 PM
u r right.i m going to do that:)

20 May 2007, 3:52 AM
Thanks a lot for your help, guys :D
I succeeded to get what I wanted with action.result. :D
But if you are intersted of the result I had before your help, jsakalos, it said me that o was undefined, so o.responseText obviously...
However, thanks for the example of the php StdClass, I didn't know about it. I am sure it will be very useful for my project.
Keep helping Newbies like, me. I am very grateful.