Extjs JSONP请求问题

Extjs JSONP请求问题,extjs,sencha-touch,sencha-touch-2,jsonp,Extjs,Sencha Touch,Sencha Touch 2,Jsonp,最近,我用一个JSONP请求替换了xmlHTTPRequest,用于我的web服务调用,但我发现由于它我得到了错误。我可以看出JSONP稍微慢一点 initialize:function(){ this.callParent(); var jsonObject = Ext.create('MyProj.library.webservice').makeJSONPRequest('top_categories_json'); Ext.getCmp('categoryList').set

最近,我用一个JSONP请求替换了
xmlHTTPRequest
,用于我的web服务调用,但我发现由于它我得到了错误。我可以看出JSONP稍微慢一点

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.');
      }
    }
  });
}

我可以看到,在执行
makeJSONPRequest
调用后,它执行下一个stateemnt而不等待JSONP请求完成,因此
jsonObject
变得未定义。在该错误之后,JSONP请求完成并打印该值。无论如何,要挂起主线程,直到JSONP请求完成。

否。对服务的调用是异步的。您确实需要将所有逻辑放入回调处理程序中。或在收到响应并处理该事件后生成事件