问题
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