Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery .get() not working in Internet Explorer

I'm having a problem with, guess what, IE8. The following code, simplified for clarity, does not work at all:

alert('before get');

$.get(getActivityURL('ActionName',{
    ts: new Date().getTime(), ...other params...}), 
{cache:false;},
    function (xml) {
    alert("in get callback");
},'xml'); // End $.get()

alert('in after get');

The getActivityUrl() outputs a valid URL with request parameters.

This works correctly in FF and Chrome. However, in IE8, this doesn't even get into the $.get() callback. I get the "before" and "after" alerts, but not the "in" alert and indeed, nothing happens and the request is NOT sent. I don't really know what to think here.

The response headers are "Content-Type:application/xml; charset:iso-8859-1" as confirmed in FF.

EDIT: $.post() doesn't work, either.

like image 657
Alessandro Avatar asked Dec 09 '22 11:12

Alessandro


1 Answers

IE is infamous for caching. So you need to make sure you are not getting a cached result.

You can disable caching globally by setting the cache property value to false in the ajaxStart method.

$.ajaxSetup({
    cache: false
});

Or If you want to eliminate the cached result in a specific ajax call, Append a unique number to the end of the url. You may use the $.now() method to get a unique number

$.get("someurl.php?" + $.now() ,function(result) {
   // do something with result
});

$.now() method return a number representing the current time.

like image 133
Shyju Avatar answered Dec 22 '22 03:12

Shyju