简体   繁体   English

jQuery的jsonp回调在一段时间后未触发

[英]jQuery's jsonp callback not firing after a while

I use jQuery's ajax method to make jsonp requests to my server (I make a request every now and then). 我使用jQuery的ajax方法向服务器发出jsonp请求(我不时发出请求)。 This usually works just fine, the server returns a response and my "success" callback function is triggered. 这通常可以正常工作,服务器返回响应,并触发我的“成功”回调函数。

Problem is, after a while, the success function stops being called, even though I receive a successful response from the server. 问题是,即使我从服务器收到成功的响应,过一会儿,成功函数也会停止调用。 When this happens, every successive jsonp request also "fails" (even from other places in the code and\\or to other paths on my server). 发生这种情况时,每个后续的jsonp请求也会“失败”(甚至从代码中的其他位置和/或到服务器上的其他路径)。

Things I've checked: 我检查过的事情:

  1. The response from the server is valid (the same as other successful responses). 来自服务器的响应是有效的(与其他成功响应相同)。

  2. The jsonpXXX callback function that jQuery creates, is indeed globally defined. jQuery创建的jsonpXXX回调函数确实是全局定义的。

  3. When I open multiple browsers on the same page, it doesn't happen in all of them. 当我在同一页面上打开多个浏览器时,并不是所有浏览器都发生这种情况。

My client side code is: 我的客户端代码是:

$.ajax({
    type: "GET",
    url: SOME_URL,
    dataType: "jsonp",
    data: {...},
    success: function(data) {
        alert("This function is not always being called :( ");
    }
});

Any ideas\\help will be greatly appreciated :) 任何想法\\帮助将不胜感激:)

You may receive a successful response from the server, but there may be some issues with the returned JSONP text. 您可能会从服务器收到成功的响应,但是返回的JSONP文本可能存在一些问题。 If there are any errors parsing the response, calling the callback function will fail. 如果解析响应时出现任何错误,则调用回调函数将失败。

Also, I suggest using this alternative solution to jQuery's implementation of JSONP which simplifies JSONP requests. 此外,我建议将此替代解决方案用于jQuery的JSONP实现,从而简化JSONP请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM