.net mvc and jquery $ .ajax on IE9

I have an ajax call for a controller that should send me an updated back view so that I can refresh my page with the updated data. But I get 304: Not Modified header back.

I tried using the no-cache option to call ajax and tried to manually add a timestamp at the end of the request url, but did not work in IE9.

This works fine on chrome without setting a caching option.

I am not sure where the problem is.

Below is the code I used, which I thought worked after adding the timestamp manually. QA stated that it does not work on its computer.

$.ajax({ url: form[0].action + "?cc="+new Date().getTime(), type: 'POST', cache: false, data: $(form).serialize() }) .success(createFilterCleanup); 
+6
source share
2 answers

Try setting the following in jQuery $ .ajax so that IE doesn't cache your ajax requests. It always worked for me.

 $.ajaxSetup({ cache: false }); 

OR

 $.ajax({ type: 'POST', cache: false }); 

http://api.jquery.com/jQuery.ajax/

"If set to false, this will cause the requested pages to not be cached by the browser. Setting the cache to false also adds the query string parameter" _ = [TIMESTAMP] to the URL string.

Below is an article with some other possible solutions: http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/

Hope this helps.

+4
source

Using the POST method instead of GET or passing an arbitrary parameter of a dummy type (for example, the current timestamp) is only a reliable method to prevent caching in IE .: (

EDITED: I read it carefully and found the added timestamp without helping you - please give a small code example to show how you add it.

0
source

Source: https://habr.com/ru/post/909675/


All Articles