【问题标题】:JSONP request issueJSONP 请求问题
【发布时间】:2013-04-25 03:00:00
【问题描述】:

最近,我已将 xmlHTTPRequest 替换为我的 Web 服务调用的 JSONP 请求,但我发现我收到了错误。我可以看到 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 请求完成。

【问题讨论】:

    标签: extjs sencha-touch sencha-touch-2 jsonp


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-03-08
      • 2013-09-15
      • 1970-01-01
      • 2011-07-12
      • 2017-04-22
      • 2013-11-09
      • 2012-10-07
      • 1970-01-01
      • 2013-12-07
      相关资源
      最近更新 更多