jQuery: catching jsonp 400 Bad Request?

旧时模样 提交于 2019-12-24 07:28:18

问题


How to catch 400 header and process error callback on jsonp request?

Or it's a bug?

Here is an example:

http://jsfiddle.net/pLuPb/

Neither error, neither complete is triggered? How to catch error?

I'm cursed? Last week i'm getting this kind of problems... :D

Guess i'll have to report this one to jQuery tracker.

Thanks ;)


回答1:


jsopn is not regular ajax request, it actually creates a script tag in ur DOM that's the reason jsonp response data is in format abc_FunctionName(data), and you gat get data directly into that function. But jQuery does that for you automatcally so you never come across that part.

To handle jsonp errors use this pluggin http://code.google.com/p/jquery-jsonp/




回答2:


JSONP is not like regular AJAX requests it uses a script tag to get the content. That being said, jQuery should be able to catch an error like 400 and its strange that its not.

You may want to add a timeout in your ajax config object: http://jsfiddle.net/pLuPb/18/

You could also do something like your own JSONP handler: http://jsfiddle.net/6j6uk/ (not sure about X-Browser support)



来源:https://stackoverflow.com/questions/6395821/jquery-catching-jsonp-400-bad-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!