Why isn't this simple bit of jQuery getJSON working in IE8?

我是研究僧i 提交于 2019-11-30 15:11:44

Ok I figured it out. Someone suggested trying a non-minified version of jQuery. I did this and stepped through the IE8s Javascript debugger. At a certain point, the following error came up:

Could not complete the operation due to error c00ce56e.

A little Googling found that it was the charset declaration I've set for my JSON data. In PHP, this was done with:

header ( 'Content-Type: text/javascript; charset=utf8' );

It turns out that IE is very particular about the charset reference ( http://forums.asp.net/t/1345268.aspx#2732852 ), so I changed it to:

header ( 'Content-Type: text/javascript; charset=UTF-8' );

And hey-presto, it works like a charm. Thanks for your help guys, you pointed me in the right direction again!

edit again — still debugging - that change to use the other function needs to have the last argument be myAjaxResponderFunc with no quotes ...

ADL
$.ajaxSetup({ cache: false }); 

You have to use check browser and version for IE8+, then use the XDomainRequest() if msie8+.

This will return a JSON String, must use jQuery.parseJSON() to create the JSON object…

Don't use getJSON!

Here's my example:

if ($.browser.msie && parseInt($.browser.version, 10) >= 8 && window.XDomainRequest) {
        // Use Microsoft XDR
        var xdr = new XDomainRequest();
        xdr.open("get", reqURL);
        xdr.onload = function() {
            var json = xdr.responseText;
            json = $.parseJSON(json);

            $.each(json.results, function(i, val) {
                    console.log(val.formatted_address);
                    var locString = val.formatted_address;
                    $.each(val.address_components, function(x, comp) {

                        if($.inArray("postal_code", comp.types) > -1) {
                            //alert("___" + comp.types);
                            zipmap[locString] = comp.short_name;
                        }

                    });

                    suggestions.push(val.formatted_address);
                });

            //alert(json.results);
        }
        xdr.send();
        add(suggestions); 
    }else {
        $.getJSON(reqURL, function(data) {

            var isZIP = new Boolean;
            console.log(data.results);
            $.each(data.results, function(i, val) {
                console.log(val.formatted_address);
                var locString = val.formatted_address;
                $.each(val.address_components, function(x, comp) {

                    if($.inArray("postal_code", comp.types) > -1) {
                        console.log("___" + comp.types);
                        zipmap[locString] = comp.short_name;
                    }

                });

                suggestions.push(val.formatted_address);
            });

            add(suggestions);  

        });
    }

requrl is the URL which you are making a request to.

Done!

Credit to: http://graphicmaniacs.com/note/getting-a-cross-domain-json-with-jquery-in-internet-explorer-8-and-later/

I just LOVE IE!

treeface

Hm...it appears that your script is running fine in IE. The only thing that appears to be breaking is your jQuery fadeOut method. I was able to find something about that here:

jquery IE Fadein and Fadeout Opacity

Basically, IE has issues with altering CSS properties when they haven't previously been declared.

Edit: Perhaps it is not running fine in IE...I might not have understood the exact process of the page load.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!