开发者

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',{开发者_如何学C
    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.


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.


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


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.


$J.get(getActivityURL('ActionName'

// End $.get()

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜