开发者

Jquery .Get() pulls NULL in Internet Explorer

开发者 https://www.devze.com 2023-01-08 16:50 出处:网络
I have a problem with an AJAX call in JQuery. It works on Chrome, FF, and Safari, but not IE. In fact in IE nothing happens at all, no errors, no data loaded.

I have a problem with an AJAX call in JQuery. It works on Chrome, FF, and Safari, but not IE. In fact in IE nothing happens at all, no errors, no data loaded.

Here is the code:

    $(document).ready(function() {

     $.ajaxSetup({ cache: false });

        $.get("ShoppingCart2.aspx", { }, function(data) {
           //query the jq object for the values

        alert(data);       
        alert($(data).find('#Items').text());


        var intI = parseInt(($(data).find('#Items').html()));

With the alert data I find all the data from the page I am making a call from, but unfortunately my dat开发者_开发问答a.find methods pull up null for IE. I'm not sure if it's the code or the browser, but I am really stuck. Thank you for the help.

Edit: I did add in the cache: false command, but still I have no luck. I really cannot understand why this won't work in IE.


Try this (once in your page/external js, before your AJAX calls):

$.ajaxSetup({ cache: false });

IE likes to cache the hell out of things, and if you were testing and had no content there at one point, chances are IE is holding onto it. Using $.ajaxSetup() and and telling it by default to not cache AJAX results should resolve this. If you're curious, it's sticking a timestamp on the URL as a cache breaker under the covers, use fiddler to see this happening.


Is it perhaps caching the AJAX? What happens if you put this before your code:

$.ajaxSetup({ cache:false });


A quick solution without coding it could be to press CTR+F5 to clear the cache upon refresh.


Well I was unable to make the .find part of the .get work in internet explorer, but I did find a way to get the ajax information I needed:

var information = $.ajax({ type: "GET", dataType: "html", url: "ShoppingCart2.aspx", data: querystring, async: false }).responseText + " ";

This passes a query string to the website then gets information from the website back into one big string. I then manipulated that string to get what I needed. Unfortunately it is a lot slower than the .get command, but it is a fix.

Thanks for the help everyone!

0

精彩评论

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