【问题标题】:JSONP request timeout in extjsextjs 中的 JSONP 请求超时
【发布时间】:2014-01-15 00:47:46
【问题描述】:

我正在向 localhost 发送 jsonp 请求以获取 json 数据。但我收到请求超时。我无法找出超时的原因。 有谁能够帮我?下面是函数

init: function() {
    var me = this;
    //making the jsonp request to fetch data
    console.log("init start");
    Ext.data.JsonP.request({
      url : 'http://localhost/TwitterApp/resources/json/Data.json',
      success: function(response){
      //populating the data in the store
        //console.log("aaaa" + response);
        var store = me.getDataStore();
        store.loadData(response);
        //console.log("on Init" + store);
        me.getStatistics().renderColumnCharts(store);
      },
      failure: function(response){
        console.log(response);
      }
    });
},

这是 Data.json 文件。它与代码中指定的位置相同

[
{
    Hashtag: "Hello",
    Value: 1
},
{
    Hashtag: "Hi",
    Value: 4
},
{
    Hashtag: "Obama",
    Value: 61
},
{
    Hashtag: "Close",
    Value: 551
},
{
    Hashtag: "MOD",
    Value: 15
},
{
    Hashtag: "winter",
    Value: 51
},
{
    Hashtag: "chadar",
    Value: 71
},
{
    Hashtag: "bottle",
    Value: 17
},
{
    Hashtag: "jaiHo",
    Value: 154
},
{
    Hashtag: "Madhur",
    Value: 144
},
{
    Hashtag: "Plank",
    Value: 142
},
{
    Hashtag: "Gft",
    Value: 1
}
]

我尝试检查网络请求。在响应正文中以文件形式显示 json 内容。但它仍然会失败并给出超时。 特此附上截图

【问题讨论】:

  • 您确定http://localhost/TwitterApp/resources/json/Data.json 存在吗?我们能看到它的输出吗?
  • @A1rPun 是的。这个文件确实存在。上面结账。我得到的输出是,它在我输出响应的故障函数中。我在控制台上得到“超时”作为输出。
  • 超时发生在 30 秒左右吗?如果是这样,可能与jsonp超时限制有关。我尝试在sencha fiddle 中模拟代码,但没有收到相同的错误。
  • @weeksdev 我尝试增加超时时间,但我仍然只收到超时错误。

标签: javascript extjs jsonp


【解决方案1】:

您的响应看起来不像 jsonp。 jsonp 的重点是它作为 javascript 执行,并且响应必须将数据包装在函数调用中。尝试发送此回复:

callback([{Hashtag: "Hello",Value: 1}, ... ]);

我不确定 extjs 如何处理 jsonp 请求。通常,回调函数的名称是可配置的,js 框架会为您处理。也许您需要将?callback=? 添加到您的url,或者在您的ext2 jsonp 请求中指定一个回调名称。也许 ext2 已经将回调参数传递给您的服务器,而您忽略它。

【讨论】:

    猜你喜欢
    • 2013-11-03
    • 1970-01-01
    • 2017-07-22
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 2013-12-07
    • 2013-04-25
    相关资源
    最近更新 更多