IE does not refresh after Ajax get/posts

前端 未结 5 790
旧时难觅i
旧时难觅i 2021-01-23 20:26

I have a small problem that I don\'t know how to deal with.

I\'ve written some jQuery post/gets which work fine in FF, Opera and Chrome. But when run from explorer (any

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-23 20:42

    What is happening is that you’re likely making a GET request to a web service for your AJAX call.

    Internet Explorer, in its wisdom, will automatically cache responses from GET requests while other browsers will let you decide if you’d like to cache the result or not. Once IE has successfully made a GET request, it will no longer even make that AJAX call until the cache expires on that object. The solutions are:

    Use POST: One option is to simply use POST requests instead of GET requests in your application. It’s usually a minor change to switch over from GET to POST on both the client and server side.

    Response Headers:

    You can also prevent caching by sending additional headers along with your response. By specifying the “Cache-Control” header with a value of “no-cache,no-store” and returning it with the web service response you can instruct the browser not to cache the result.

    jQuery:

    Finally, if you’re using jQuery, you can specify that you don’t want to cache the response from your AJAX requests either across the board using the $.ajaxSetup() method or on a per request basis as cache:false.

提交回复
热议问题