简体   繁体   中英

SCRIPT5022: InvalidAccessError xmlhttprequest

I'm having a problem with my javaScript when I try to send GET. With xmlhttprequest I don't reach the WebServices, but I can reach it with Soap UI.

The error code in mode debug in IE11 is :

SCRIPT5022: InvalidAccessError

The code is the following:

var xmlToSend = "<?xml version='1.0' encoding='utf-8'?>";
xmlToSend += "<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:ws='some xmlns'>";
xmlToSend += "<soap:Header/> ";
xmlToSend += "<soap:Body>";
xmlToSend += "<ws:searchMultisPolicy>";
xmlToSend += "<ws:xmlRequest>";
xmlToSend += "<![CDATA[";
xmlToSend += "<searchMultisPolicyReq>";
xmlToSend += "<wsHeader>";
xmlToSend += "<user>B12345674280010001</user>";
xmlToSend += "<logginDate>27/04/2015</logginDate>";
xmlToSend += "<roles>170</roles>";
xmlToSend += "</wsHeader>";
xmlToSend += "<params>";
xmlToSend += "<idProveedor>02</idProveedor>";
xmlToSend += "<nifTomador>12341234D</nifTomador>";
xmlToSend += "<fechaOcurrencia>2015-04-27T10:00:00</fechaOcurrencia>";
xmlToSend += "<poliza>80208813</poliza>";
xmlToSend += "<razonSocial></razonSocial>";
xmlToSend += "</params>";
xmlToSend += "</searchMultisPolicyReq>";
xmlToSend += "]]>";
xmlToSend += "</ws:xmlRequest>";
xmlToSend += "</ws:searchMultisPolicy>";
xmlToSend += "</soap:Body>";
xmlToSend += "</soap:Envelope>";

var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
xmldoc.loadXML(xmlToSend);
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = state_Change;
xmlhttp.open(
                "POST",
                "some WebService",
                0, "user", "pwd");
xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
xmlhttp.setRequestHeader("action", "urn:searchMultisPolicy");
xmlhttp.setRequestHeader("Content-Type", "application/soap+xml");
xmlhttp.setRequestHeader("charset", "UTF-8");
xmlhttp.setRequestHeader("Accept-Encoding", "application/soap+xml");
xmlhttp.send(xmldoc);

function state_Change() {
    if (xmlhttp.readyState == 4) {
        // if "OK"
        if (xmlhttp.status == 200) {
            alert("OK");
            var objResponse = document.getElementById("responseDiv");
            objResponse.innerText = xmlhttp.responseXML.xml;
        } else {
            alert("Problema recibiendo XML"+" "+xmlhttp.status);
        }
    }
}   

Access-Control-Allow-Origin is a response header, not a request header.

You have to configure the system you are making the request to to allow you to make a cross origin request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM