简体   繁体   English

jQuery .ajax()JSONP响应上的间歇性TypeError

[英]Intermittent TypeError on jQuery .ajax() JSONP response

I am intermittently receiving an Uncaught TypeError: undefined is not a function response on my jQuery .ajax() JSONP response. 我间歇性地收到Uncaught TypeError: undefined is not a function我的jQuery .ajax() JSONP响应上Uncaught TypeError: undefined is not a function响应。 The call is returning the JSON with no issue but when jQuery reads it, I sometimes receive the error. 该调用返回的JSON没有问题,但是当jQuery读取它时, 有时会收到错误消息。

Here's an example of a request that jQuery is creating: 这是jQuery创建的请求的示例:

http://www.requestdomain.com/json/request?callback=jQuery1910423432748997584_1397740628595&[my params]&_=1397740628596

And the failed response that is coming back: 失败的响应又回来了:

jQuery1910423432748997584_1397740628595({properly formated JSON})

The error is literally being generated on the response itself, and not any scripts interacting with it. 错误实际上是在响应本身上生成的,而不是与其交互的任何脚本。 I can run it a few times and it'll fail randomly, but the responses of passing and failing requests are identical aside from the randomly generated numbers that jQuery is appending. 我可以运行几次,它将随机失败,但是除了jQuery附加的随机生成的数字之外,传递和失败请求的响应是相同的。

Has anyone experienced this before? 有谁之前经历过这个吗?

For me it was because the browser (Canary) doesn't allow more than 6 concurrent connections tho the same hostname. 对我来说,这是因为浏览器(Canary)不允许使用同一主机名进行6个以上的并发连接。

It's a restriction many browsers have. 这是许多浏览器的限制。 For most of them the limit is 6 but you can find the exact list here on browserscope.org . 对于其中大多数限制,该限制为6,但您可以在browserscope.org上找到确切的列表

You can also test your own browser version . 您也可以测试自己的浏览器版本

Adding a delay/debounce between each requests solved it. 在每个请求之间添加延迟/反跳可以解决该问题。

If you can't do that there is another trick which consists in requesting from different hostname. 如果您无法执行此操作,则还有另一种技巧,即从不同的主机名进行请求。 To do so you set mirrors do host your assets or datas. 为此,您可以设置镜像来托管您的资产或数据。 Just know that there is also a limitation for concurrent connections on different hotsnames (10 for chrome 32). 只需知道不同的hotsname上的并发连接也有一个限制(chrome 32为10)。

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

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