与IE浏览器11奇怪的AJAX错误奇怪、浏览器、错误、IE

2023-09-10 16:01:40 作者:眼睛爱哭,但不会输。

我目前工作的一个纯粹的HTML和JavaScript驱动的Web应用程序,使用CORS的消费远程Web服务,但目前有IE浏览器11的麻烦一个GET请求。有趣的是,我们已经把它工作正常在IE8 / 9/10只是没有11

I'm currently working on a purely HTML and JavaScript driven web app that uses CORS for consuming a remote web service but currently having trouble with IE 11 making a GET request. The funny thing is we've got it working fine in IE8/9/10 just not 11.

现在的问题是,IE浏览器11出现超时,而不是等待服务器的响应。 Ajax调用很简单:

The problem is that IE 11 appears to timeout and not wait for a response from the server. The ajax call is simply:

$.ajax(url, {
    dataType: 'json',
    complete: complete,
    type: 'GET',
    global: true,
    success: success,
    crossDomain: true,
    xhrFields: {
        withCredentials: true
    }
});

在网络选项卡,并使用招我可以看到IE从来没有发送请求。

In the network tab and using Fiddler I can see IE never even sends the request.

有没有人有什么想法吗?

Does anyone have any ideas please?

修改的:我忘了提我已经尝试过缓存:假的。我也发现了一些很奇怪的,如果我在开发工具切换文档模式从边缘到9,然后再回来的通话效果,每次,我已经清除IE浏览器并重新启动它,高速缓存是否是真的还是假的,甚至后。很奇怪的。 :\

EDIT: I forgot to mention I've already tried cache: false. I've also found something very strange in that if I switch document mode in dev tools from Edge to 9 then back again the call works everytime, even after I've cleared IE and restarted it, whether cache is true or false. Very bizarre. :\

推荐答案

IE是著名的缓存。确保你没有得到一个缓存的响应。您可以设置缓存属性值或添加了独特的时间戳的URL,以便它不会一个缓存的响应。您可以使用 $。现在() 的方法来获得独特的时间戳。

IE is famous for caching. Make sure you are not getting a cached response. You can either set the cache property value to false or add a unique timestamp to the url so that it will not be a cached response. You may use the $.now() method to get a unique timestamp.

设置缓存属性

$.ajax(url, {
    dataType: 'json',
    cache : false,
    //Other things ...
}

添加了独特的时间戳网址

var url="somePage.php?"+$.now();
//Use this url now for making the ajax call

$。现在()法是一种简写由前pression返回的数字(新日期).getTime( )