码迷,mamicode.com
首页 > Web开发 > 详细

IE8 AJAX 不能正常工作 解决办法

时间:2014-10-16 19:08:42      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

function crossDomainAjax(url, successCallback) {

    // IE8 & 9 only Cross domain JSON GET request
    if (XDomainRequest in window && window.XDomainRequest !== null) {

        var xdr = new XDomainRequest(); // Use Microsoft XDR
        xdr.open(get, url);
        xdr.onload = function () {
            var dom = new ActiveXObject(Microsoft.XMLDOM),
                JSON = $.parseJSON(xdr.responseText);

            dom.async = false;

            if (JSON == null || typeof (JSON) == undefined) {
                JSON = $.parseJSON(data.firstChild.textContent);
            }

            successCallback(JSON); // internal function
        };

        xdr.onerror = function () {
            _result = false;
        };

        xdr.send();
    }

        // IE7 and lower can‘t do cross domain
    else if (navigator.userAgent.indexOf(MSIE) != -1 &&
             parseInt(navigator.userAgent.match(/MSIE ([\d.]+)/)[1], 10) < 8) {
        return false;
    }

        // Do normal jQuery AJAX for everything else          
    else {
        $.ajax({
            url: url,
            cache: false,
            dataType: json,
            type: GET,
            async: false, // must be set to false
            success: function (data, success) {
                successCallback(data);
            }
        });
    }
}
    crossDomainAjax(url, function (data) {
            if ("1" != data) {//data.message
                alert(data);
            } else {
                alert("发送成功!");
                if (isTree == "1") {
                    searchTreedata();
                } else {
                    searchdata();
                }

            }
        });

记录下,下次用

IE8 AJAX 不能正常工作 解决办法

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/flyfish2012/p/4029212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!