jQuery-ajaxTransport-XDomainRequest icon indicating copy to clipboard operation
jQuery-ajaxTransport-XDomainRequest copied to clipboard

IE9使用此插件,依然进了error方法!

Open weixiaoting opened this issue 6 years ago • 7 comments

image

weixiaoting avatar Sep 30 '18 06:09 weixiaoting

我的也是,ie8也不工作 如果你的请求代码不多,试试下面的:

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
        console.log(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;
            console.log(_result);
        };

        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);
            }
        });
    }
}

mu-mx avatar Sep 30 '18 07:09 mu-mx

我的也是,ie8也不工作如果你的请求代码不多,试试下面的:

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
        console.log(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;
            console.log(_result);
        };

        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);
            }
        });
    }
}

你是这样解决的??那我试试吧,本来说已经放弃IE这个了,提示让他升级来着呢

weixiaoting avatar Sep 30 '18 07:09 weixiaoting

我的也是,ie8也不工作如果你的请求代码不多,试试下面的:

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
        console.log(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;
            console.log(_result);
        };

        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);
            }
        });
    }
}

image xdr.open('POST', url);这里会拒绝访问

weixiaoting avatar Sep 30 '18 08:09 weixiaoting

应该是没对post 进行处理 ie8~9还要跨域 想想就可怕

mu-mx avatar Sep 30 '18 08:09 mu-mx

应该是没对post 进行处理 ie8~9还要跨域 想想就可怕

我以为你解决了呢?你不是IE9解决了??微信方便加下吗?我的微信:w1083775465

weixiaoting avatar Sep 30 '18 08:09 weixiaoting

大家都不容易啊,这年头了还要支持IE8~9。今天正好遇到这样的问题, $.Ajax中设置"dataType: 'jsonp' ",就会以Get方式发送请求,在服务端增加此方式的处理方法即可。

coding-and-trading avatar Oct 25 '18 07:10 coding-and-trading

so!大家有办法吗,除了和后端pk

Silencer-1984 avatar Aug 11 '20 10:08 Silencer-1984