SCRIPT5: Access is denied in IE9 on xmlhttprequest

后端 未结 11 1857
太阳男子
太阳男子 2020-11-28 07:42
var xhttp=new XMLHttpRequest();
xhttp.open(\'GET\', \'foo.xml\', false);

F12 pops back: SCRIPT5: Access is denied. on Line 95, which is

相关标签:
11条回答
  • 2020-11-28 08:20

    Most likely, you need to have the Javascript served over SSL.

    Source: https://www.parse.com/questions/internet-explorer-and-the-javascript-sdk

    0 讨论(0)
  • 2020-11-28 08:22

    I had faced similar issue on IE10. I had a workaround by using the jQuery ajax request to retrieve data:

    $.ajax({
        url: YOUR_XML_FILE
        aync: false,
        success: function (data) {   
            // Store data into a variable
        },
        dataType: YOUR_DATA_TYPE,
        complete: ON_COMPLETE_FUNCTION_CALL
    });
    
    0 讨论(0)
  • 2020-11-28 08:28
      $.ajax({
            url: '//freegeoip.net/json/',
            type: 'POST',
            dataType: 'jsonp',
            success: function(location) {
                alert(location.ip);
            }
        });
    

    This code will work https sites too

    0 讨论(0)
  • 2020-11-28 08:33

    I think that the issue is that the file is on your local computer, and IE is denying access because if it let scripts have access to files on the comp that the browser is running on, that would be a HUGE security hole.
    If you have access to a server or another comp that you could use as one, maybe you could try putting the files on the that, and then running the scripts as you would from a website.

    0 讨论(0)
  • 2020-11-28 08:34

    Probably you are requesting for an external resource, this case IE needs the XDomain object. See the sample code below for how to make ajax request for all browsers with cross domains:

    Tork.post = function (url,data,callBack,callBackParameter){
        if (url.indexOf("?")>0){
            data = url.substring(url.indexOf("?")+1)+"&"+ data;
            url = url.substring(0,url.indexOf("?"));
        }
        data += "&randomNumberG=" + Math.random() + (Tork.debug?"&debug=1":"");
        var xmlhttp;
        if (window.XDomainRequest)
        {
            xmlhttp=new XDomainRequest();
            xmlhttp.onload = function(){callBack(xmlhttp.responseText)};
        }
        else if (window.XMLHttpRequest)
            xmlhttp=new XMLHttpRequest();
        else
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200){
                Tork.msg("Response:"+xmlhttp.responseText);
                callBack(xmlhttp.responseText,callBackParameter);
                Tork.showLoadingScreen(false);
            }
        }
        xmlhttp.open("POST",Tork.baseURL+url,true);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send(data);
    }
    
    0 讨论(0)
  • 2020-11-28 08:35

    This example illustrate how to use AJAX to pull resourcess from any website. it works across browsers. i have tested it on IE8-IE10, safari, chrome, firefox, opera.

    if (window.XDomainRequest) xmlhttp = new XDomainRequest();
    else if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
    else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    
    xmlhttp.open("GET", "http://api.hostip.info/get_html.php", false);
    xmlhttp.send();
    
    hostipInfo = xmlhttp.responseText.split("\n");
    var IP = false;
    for (i = 0; hostipInfo.length >= i; i++) {
        if (hostipInfo[i]) {
    
            ipAddress = hostipInfo[i].split(":");
            if (ipAddress[0] == "IP") {
                IP = ipAddress[1];
            }
        }
    }
    return IP;
    
    0 讨论(0)
提交回复
热议问题