Reputation: 9979
Recently I have replaced xmlHTTPRequest
with a JSONP request for my web service calls, but I found that I'm getting errors due to it. I could see that JSONP is a little slower.
initialize:function(){
this.callParent();
var jsonObject = Ext.create('MyProj.library.webservice').makeJSONPRequest('top_categories_json');
Ext.getCmp('categoryList').setData(jsonObject.info);
console.log(jsonObject.info);
}
makeJSONPRequest: function(urlx, postparams) {
Ext.data.JsonP.request({
params:{
params: Ext.JSON.encode(postparams)
},
success: function(result) {
console.log('JSON RES');
console.log(result.info);
if (result) {
//return JSON.parse(result);
return result;
} else {
Ext.Msg.alert('Error', 'There was an error retrieving the weather.');
}
}
});
}
I could see that after executing the makeJSONPRequest
call, it executes the next stateemnt without waiting for the JSONP request to finish, so jsonObject
becomes undefined. After that error the JSONP request finishes and prints the value. Anyway to suspend the main thread until the JSONP request finishes.
Upvotes: 0
Views: 650
Reputation: 17850
No. Calls to your service are async. You really need to put all logic in the callback handler. Or generates an event after you receive a response and handle that event.
Upvotes: 1