在jQuery v1.x中从$ .ajax许诺中捕获403 [英] Catching 403 from $.ajax promise in jQuery v1.x
问题描述
我在从jQuery v1.x中的$.ajax
许诺中捕获403时遇到问题.
相同的代码
$.ajax({
dataType: 'jsonp',
url: 'http://www.checkupdown.com/accounts/grpb/B1394343/',
type: 'GET'
}).then(function () {
console.log('success', arguments)
}, function () {
console.log('error', arguments)
});
在jQuery v2.x中拒绝预期的,但没有记录readyState == 1
).
示例分别使用2.1.3和1.11.3 jQuery版本.
为什么会发生这种情况? jQuery v1是否可以解决?
它们的执行方式有所不同,因为在1.11.x中,错误事件处理程序未附加到script标记,相反,您所拥有的只是一个onload或onreadystatechange处理程序. /p>
https://github.com/jquery/jquery/blob/1.11.3/src/ajax/script.js#L57
https://github.com/jquery/jquery/blob/2.1.3/src/ajax/script.js#L44
除了使用超时或自己执行jsonp请求外,没有其他解决方法.
I'm having problems with catching 403 from $.ajax
promise in jQuery v1.x.
The same code
$.ajax({
dataType: 'jsonp',
url: 'http://www.checkupdown.com/accounts/grpb/B1394343/',
type: 'GET'
}).then(function () {
console.log('success', arguments)
}, function () {
console.log('error', arguments)
});
rejects the promise as expected in jQuery v2.x but logs nothing in jQuery v1.x (the promise has readyState == 1
).
The examples use 2.1.3 and 1.11.3 jQuery versions respectively.
Why exactly does this happen? Is it solvable for jQuery v1?
They perform differently because in 1.11.x, an error event handler is not attached to the script tag, instead all you have is an onload or onreadystatechange handler.
https://github.com/jquery/jquery/blob/1.11.3/src/ajax/script.js#L57
https://github.com/jquery/jquery/blob/2.1.3/src/ajax/script.js#L44
There is no workaround other than using a timeout or performing the jsonp request yourself.
这篇关于在jQuery v1.x中从$ .ajax许诺中捕获403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!