Jquery ajax, when periodicaly called, doesnt work

2020-03-24 02:54发布

I am currently doing the same ajax request using jQuery every 2sec. For some reason, on IE8 it only work the first time. Each following request automatically seems to go to the onSuccess function, with the same result as the first request.

The same code work perfeclty on FF3 and Chrome.

Is anybody aware of that bug and how to hack around it? Or am I simply doing something wrong?

3条回答
我想做一个坏孩纸
2楼-- · 2020-03-24 03:36

IE has a caching feature... it's possible that it has just cached your request. Make sure you append something like a random number to your query string, like so:

var url = "/yoururl.html";
url = url + "&random=" + Math.random();
查看更多
不美不萌又怎样
3楼-- · 2020-03-24 03:43

Just so you know $.ajax has a cache attribute that, when set to false does exactly what Jason is doing, namely, includes a random parameter that means no requests get cached. It's a little more elegant than doing it yourself

查看更多
老娘就宠你
4楼-- · 2020-03-24 03:47

I have just encountered the same thing and have fixed it by setting the "cache" property of your ajax function call to false.

        $.ajax({
            url: "/ws/inventory/checkavailability/",
            async: false,
            dataType: 'json',
            cache:false,
            success: function (data) {
                //so something interesting
            }, error: function (error) {
                //display error?
            }
        });
查看更多
登录 后发表回答