XDomainRequest在ie8& IE9

时间:2016-09-08 09:22:48

标签: javascript jquery ajax internet-explorer internet-explorer-8

我浏览了很多次,我多次尝试过,我完全感到心烦意乱,请帮助我。我尝试在ie8中发送带有跨域的请求,但它没有进入服务器端。

我搜索&参考并获得许多链接,这些是以下显示

https://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx http://www.codeproject.com/Questions/708881/Cross-domain-ajax-response-with-IE-and-IE http://cypressnorth.com/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/

以及更多链接

我的代码显示在下面

<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>VAS</title>
    <meta name="description" content="" />
    <script src="js/jquery-1.12.1.min.js" type="text/javascript"></script>
    <script>
    $(document).ready(function(){
         (function(w) {
        var g = {};
        g.geoLocate = function(d, e) {

            if ('XDomainRequest' in window && window.XDomainRequest !== null) {

                var xdr = new XDomainRequest();
                console.log("started");
                xdr.open("GET", "https://someDomain/?k=sometoken");             
                xdr.onprogress = function(){
                console.log("ON progress");
                };
                xdr.onerror = function(){
                console.log("Error"); // i did not get here
                };
                xdr.onload = function(){
                console.log("onload function");// i did not get here
                };
                setTimeout(function(){
                xdr.send();
                },0);
            } 

            // 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 "does not support";
            }    

            // Do normal jQuery AJAX for everything else          
            else {
            console.log("Else");
                $.ajax("https://someDomain/?k=sometoken", {
                    contentType: 'application/json; charset="UTF-8"',
                    crossDomain: true,
                    dataType: "json",
                    data: f,
                    error: function(a, b, c) {
                        console.log("Error"+a+b+c);
                    },
                    success: function(a, b, c)
                    {
                        console.log("Sucess"+a+b+c)
                    },
                    type: "GET",
                    timeout: 10000
                });
            }
        };
        w.idns = g
        })(window);
    });


    </script>
    </head>
<body>
    <div id="altContent">
        <h1>VAS</h1>
    </div>
</body>
</html>

上面显示了ajax调用或使用chrome和firefox浏览器正常工作,但我需要运行ie8和ie9浏览器,请帮助我。我使用了jquery.1.12.1

0 个答案:

没有答案
相关问题