4

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.

Alessandro
  • 601
  • 3
  • 11
  • 26
  • Could you provide the complete function call, rather than one with bits missed out? Your current code wouldn't work in any browser. – lonesomeday Jan 14 '11 at 16:08
  • This exact code works in every browser save IE8. The "getActivityUrl(...)" returns a valid URL. – Alessandro Jan 17 '11 at 09:06

5 Answers5

12

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.

Czar Pino
  • 6,258
  • 6
  • 35
  • 60
Shyju
  • 214,206
  • 104
  • 411
  • 497
1

I'm not sure if it is a problem but try to remove ";" in {cache:false}

IE doesn't like any additional stuff in {}, eg {a:a,b:b,c:c,} will work in FF but not in IE

Ivan
  • 3,567
  • 17
  • 25
1

I think so there is Cache problem in IE.

So add Math.random(), one more parameter at the end like "&mathRandom="+Math.random(); Because IE will recognise same request as previous one so it will give data from cache instead of firing request.

Novelist
  • 469
  • 4
  • 15
Lalit Bhudiya
  • 4,332
  • 4
  • 26
  • 32
0
$J.get(getActivityURL('ActionName'

// End $.get()

Is this correct? I mean $J... Are you using more than one JS framework or something?

atzu
  • 424
  • 3
  • 14
  • Yeah, forgot to mention that, it is correctly "no-conflicted" throughout the application. Anyways, I just edited the question. – Alessandro Jan 14 '11 at 16:03
0

have u tried:

$.ajax({
  url: getActivityURL('ActionName',{ts: new Date().getTime(), ...other params...}),
  data: data,
  success: function (xml) {
               alert("in get callback");
            },
  dataType: 'xml'
});

Just a guess

EDIT:

I found a interesting thread that might help you, check this out:

jQuery issue in Internet Explorer 8

Community
  • 1
  • 1
Arthur Neves
  • 11,840
  • 8
  • 60
  • 73