jquery ajax ie9 出错,IE9 JQuery.ajax引发了神秘错误(IE9 JQuery.ajax throws mystery error)

在IE9中,遇到一个独特的AJAX错误,请求在被发送之前就失败了,状态为0,错误对象的`readyState`为4。尽管不是跨域请求,但可能与本地代理有关。其他浏览器正常工作,提示问题可能在于jQuery/IE组合对URL编码的处理。已尝试在`beforeSend`函数中正确设置URL,但问题依然存在。寻求解决方案。
摘要由CSDN通过智能技术生成

I'm experiencing a difficult ajax error in IE9. I will say up-front that this is not technically a cross-domain request so I'm sure that is not the problem.

Edit: It appears that the problem may be related to a same-domain request being treated as cross-domain, though it is not clear why (see comments).

I'm using a local proxy to make cross-domain ajax requests, and the url I use looks like http://localhost/proxy/?target=..... All good browsers are happy with this but IE immediately returns an error before the request is even dispatched (I have verified this using Fiddler and IE's developer tools network capture).

When I inspect the error object passed to JQuery's ajax.error callback its isRejected() function returns true, but I can't find out what would cause a request to be rejected. The error object's readyState is 4 (implying the request is complete?), status is 0 and statusText is "error".

I'm building my request a bit like this:

$.ajax(url, {

data: {...list of parameters...},

dataType: 'json',

type: 'GET',

success: function() { ... },

error: function() { ... },

beforeSend: proxy.beforeRequestSend,

timeout: 35000

});

The proxy.beforeRequestSend function looks like this:

this.beforeRequestSend = function(XHR, settings) {

if(that.proxyRequired(settings.url)) {

// I've also tried using the full url (http://localhost/proxy/?...)

settings.url = 'proxy/?target=' + encodeURIComponent(settings.url);

}

};

Does anyone know what would cause the request to fail outright in IE9? Unfortunately I don't have access to IE8 or 7 for testing but I assume they would behave the same. The fact that JQuery's ajax error handler is invoked suggests that the error is not occuring while I am building the request, but when it is supposedly executed. All other browsers working correctly tells me that the fundamentals are correct.

I have previously read that the JQuery / IE combo has issues url-encoding some characters, but if I alert settings.url at the end of the beforeSend function the target URL is correctly encoded (this also tells me that that.proxyRequired(settings.url) returns true).

Any input much appreciated.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值