I’m calling a web service with my Sencha Touch mobile app:
Ext.regModel('BaseResponse', {
idProperty: 'ResponseTime',
fields: [
{ name: 'ErrorMessage', type: 'string' },
{ name: 'ResponseTime', type: 'date', dateFormat: 'c' },
{ name: 'StatusCode', type: 'string' },
{ name: 'Success', type: 'string' }
]
});
var declineResult = new Ext.regStore('declineResult',
{
model: 'BaseResponse',
proxy : {
type : 'ajax',
dataType: "json",
url : App.BaseURL + '/SetJobResponse/' + options.jobId + '/' + STCID +'/' + options.OJSStatusID + '/' + device.uuid,
reader: new Ext.data.JsonReader ({
type: 'json'
})
},
listeners:
{
'load': function(store,records,successful)
{
alert(records.length);
//alert('response message:' + Ext.StoreMgr.get("declineResult").getAt(0).ErrorMessage);
},
'loadexception': function()
{
alert('There was a load exception');
}
}
});
Ext.StoreMgr.get("declineResult").load();
Here’s the JSON returned by the URL if I just browse to it:
{"ErrorMessage":"You are not authorised","ResponseTime":"\/Date(1321447985287)\/","StatusCode":401,"Success":false}
However even though my load event shows Successful=true, records is empty (length of 0).
The exception event is not being fired.
How can I diagnose this further? I’m using Eclipse with Sencha Touch and Phonegap with an android emulator. Is there any way to see what’s being returned to it?
I found that Sencha 1.x doesn’t seem to be able to handle these responses:
What I ended up doing was using Ext.override to implement proper client-side responses to these server responses.
To get this working, you have to debug (use the Sencha debug libraries and place breakpoints there, using your JavaScript debugger) and see where your app crashes. You’ll then find Ext.data.Reader in the callstack of your crash.
The next step is to override its member functions like extractData and readRecords to implement the proper functionality (like null pointer checks where necessary).
[edit] Relevant link:
http://docs.sencha.com/touch/1-1/source/Reader.html#Ext-data-Reader