Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
weixiaoting opened this issue Sep 30, 2018 · 7 comments
Open

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

weixiaoting opened this issue Sep 30, 2018 · 7 comments

Comments

@weixiaoting
Copy link

image

@mu-mx
Copy link

mu-mx commented Sep 30, 2018

我的也是,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);
            }
        });
    }
}

@weixiaoting
Copy link
Author

我的也是,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
Copy link
Author

我的也是,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);这里会拒绝访问

@mu-mx
Copy link

mu-mx commented Sep 30, 2018

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

@weixiaoting
Copy link
Author

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

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

@coding-and-trading
Copy link

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

@Silencer-1984
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants