SCRIPT5: Access is denied in IE9 on xmlhttprequest

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

提交回复
热议问题