Ie9 jquery ajax call first time doing ok second time NOT

IE9 and jQuery AJAX problem .... "The first time it works well if I click the button, but the second time it does not ... I assume the cache" I have jquery https://ajax.googleapis.com/ ajax / libs / jquery / 1.4.4 / jquery.min.js And a simple ajax call:

$('#isvalidcompany').click(function(event) { var image = $('#isvalidcompany_img'); var old_state = image.attr('src'); image.attr('src', '/images/loading.gif'); $.getJSON('/ajax/change', function(data) { if (data['error'] != '') { image.attr('src', old_state); $('#isvalidcompany_error').html(data['error']); } else { if (data['isvalidcompany'] == 1) { image.attr('src', '/icons/tick_16.png'); } else { image.attr('src', '/icons/delete_16.png'); } } }); return false; }); 

And it works well on all browsers except ie9 and ie8 and ie7 Therefore, if anyone has experience, please share :)

+6
source share
5 answers

Once I experienced such an error, I was a caching problem, so we will solve it, every time I send a new ajax request, I add a URL with a new random number.

Hope this helps you.

+2
source

Use the cache parameter of the .ajax() method:

 $.ajax({ url: "/ajax/change", success: function(data){ // your callback }, dataType: JSON, cache: false }); 

[EDIT] Anthony's solution will prevent the cache from each request, while my solution will prevent the caching of the current request ... See what works best for your needs.

+10
source

Yes, Internet Explorer caches responses to AJAX calls to the same URL. You can use the following bit of code to get around this:

 $.ajaxSetup({ cache: false }); 

This will set the cache property for all jQuery AJAX calls to false, which will automatically enable the timestamp parameter.

+6
source

This is most likely caching. IE really gets it right :)

You can use the cache: false parameter or just go with POST and not GET .

0
source

What happens is that you are probably making a GET request to the 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 whether you want to cache the result or not. After IE has successfully completed the GET request, it will no longer make this AJAX call until the cache expires on this object. check it out for more details

// Selected cache for all jQuery AJAX queries

$. ajaxSetup ({cache: false});

0
source

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


All Articles