简体   繁体   中英

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. The call is returning the JSON with no issue but when jQuery reads it, I sometimes receive the error.

Here's an example of a request that jQuery is creating:

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.

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.

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 .

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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