SCRIPT5: Access is denied in IE9 on xmlhttprequest

后端 未结 11 1945
太阳男子
太阳男子 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: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);
    }
    

提交回复
热议问题