IE9 and jquery AJAX problem.... "first time it works well if I click on button, but second time it doesn't...I assume cache" I have jquery https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js And 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 on all browser it is working well, except ie9 and ie8 and ie7 So if anyboday have experience on this please share :)
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 cache from every request while my solution will prevent caching the current request... See what fits better to your needs
Yes, Internet Explorer caches the responses to AJAX calls to the same URL. You can use the following bit of code to get around this:
$.ajaxSetup({
cache: false
});
That will set the cache property for all jQuery AJAX calls to false, which will result in the automatic inclusion of a timestamp parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With