PDA

View Full Version : How can I read the response from an AJAX call



Kurt001
8 Mar 2011, 7:30 AM
I am trying to find out what the response.
How can I read the vars response and opts:


var makeAjaxRequest = function() {
Ext.getBody().mask('Loading...', 'x-mask-loading', false);
Ext.Ajax.request({
url: 'http://www.myServer.com/requestURL',
method: 'POST',
params :{fun:'srnDeviceLogin',did:'66:66:00:00:00:EE'},
success: function(response, opts) {
alert('do some successful stuff');
},
failure: function(response, opts) {
alert(response.status);
}
});
};

Can anyone help?

MWagner
8 Mar 2011, 8:39 AM
The API Docs tell me the following:



Ext.Ajax.request({
url: 'ajax_demo/sample.json',
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});

Source: http://dev.sencha.com/deploy/touch/docs/?class=Ext.Ajax

Maybe this helps you.

Kurt001
14 Mar 2011, 2:25 AM
A very important tool became the command

var jsonResponse = Ext.decode(response.responseText);
console.dir(jsonResponse);

This outputs the Object that was returned and helped me to analyze it.