Javascript 为什么跨域jQuery SOAP请求被拒绝,即使;“跨域”;属性是否已设置?

Javascript 为什么跨域jQuery SOAP请求被拒绝,即使;“跨域”;属性是否已设置?,javascript,jquery,soap,wsdl,cross-domain,Javascript,Jquery,Soap,Wsdl,Cross Domain,我有一个jquerysoap请求,由于某种原因,它不起作用。困扰我的是,我已经考虑了CORS请求所需的一切,但它返回的只是状态0和状态文本“Error” 我知道这可能是一个徒劳无益(而且愚蠢)的问题,但请你看一看,找出我不能回答的问题?我真的很高兴,因为这让我恼火了好几天。代码已经是一个完整的HTML文件,带有JS,可以按原样使用,只需调整jQuery路径 你好,杰森 <html> <head> <title>SOAP JavaScript Client Te

我有一个jquerysoap请求,由于某种原因,它不起作用。困扰我的是,我已经考虑了CORS请求所需的一切,但它返回的只是状态0和状态文本“Error”

我知道这可能是一个徒劳无益(而且愚蠢)的问题,但请你看一看,找出我不能回答的问题?我真的很高兴,因为这让我恼火了好几天。代码已经是一个完整的HTML文件,带有JS,可以按原样使用,只需调整jQuery路径

你好,杰森

<html>
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript" src="jquery-2.1.1.min.js" ></script>
<script type="text/javascript" >
    function fnc_soap() {
        var request = 
        '<?xml version="1.0" encoding="utf-8"?> ' +
        '<soap12:Envelope ' +
        'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
        'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
        'xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" ' +
        'soap12:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> ' +
            '<soap12:Body> ' +
                '<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/"> ' +
                    '<Celsius>37</Celsius> ' +
                '</CelsiusToFahrenheit> ' +
            '</soap12:Body> ' +
        '</soap12:Envelope>';

        var url = "http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit";
        jQuery.ajax({
            type: "POST",
            url: url,
            data: request,
            dataType: "xml",
            crossDomain: true,
            processData: true,
            contentType: "text/xml; charset=\"utf-8\"",
            xhrFields: {
                withCredentials: true
            },
            beforeSend: function(xhr) {
                // xhr.setRequestHeader('Access-Control-Allow-Methods', 'OPTIONS, TRACE, GET, HEAD, POST');
                xhr.withCredentials = true;
            },
            headers: {
                SOAPAction: "http://www.w3schools.com/webservices/CelsiusToFahrenheit"
            },
            success: function (msg) {
                alert("Works!");
            },
            error: function (msg) {
                alert("Failed: " + msg.status + ": " + msg.statusText);
            }
        });
    }
</script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="fnc_soap();" ></input>
        </div>
    </form>
</body>
<html>

soapjavascript客户端测试
函数fnc_soap(){
var请求=
' ' +
' ' +
' ' +
' ' +
'37 ' +
' ' +
' ' +
'';
变量url=”http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit";
jQuery.ajax({
类型:“POST”,
url:url,
数据:请求,
数据类型:“xml”,
跨域:是的,
processData:对,
contentType:“text/xml;字符集=\“utf-8\”,
xhrFields:{
证书:正确
},
发送前:函数(xhr){
//setRequestHeader('Access-Control-Allow-Methods','OPTIONS,TRACE,GET,HEAD,POST');
xhr.withCredentials=true;
},
标题:{
SOAPAction:“http://www.w3schools.com/webservices/CelsiusToFahrenheit"
},
成功:功能(msg){
警惕(“工作!”);
},
错误:函数(msg){
警报(“失败:“+msg.status+”:“+msg.statusText”);
}
});
}
通过Firebug分析响应,XML部分中有一些奇怪的错误消息:

XML-Verarbeitungsfehler: Nicht übereinstimmendes Tag. Erwartet: </input>. Adresse: moz-nullprincipal:{e5ad2994-5e6d-4c61-9c47-7cad2f80f169} Zeile Nr. 71, Spalte 96:
...frmInput" type="text" size="50" name="Celsius"></td>
...-------------------------------------------------^
XML Verarbeitungsfehler:Nichtübereinstimmendes标记。埃尔瓦特:。地址:moz nullprincipal:{e5ad2994-5e6d-4c61-9c47-7cad2f80f169}第71号泽伊勒,第96页:
…frmInput“type=“text”size=“50”name=“cellices”>
...-------------------------------------------------^
…这仅仅意味着“XML处理错误:不匹配的标记”。应为第71行第96列“。这是服务器端错误吗?因为它不能来自我的缩小HTML领域,因为它没有表


您好,jaySon

看起来您得到的响应来自此页面:是的,我的印象是,为了得到正确的结果,应该是这样的。这只是他们的测试页面。到那里键入一些数字,然后按“调用”-您将得到一个XML响应。xxx-因此,在我看来,您调用了错误的UR你应该改为调用。好吧,即使有那个URL,它仍然会给我同样的错误:“跨源请求被阻止“。跨域请求要求服务器设置正确的CORS标头才能工作。如果您使用的W3API不提供CORS支持,则在没有服务器端代理的情况下,您无法通过JavaScript访问页面上的资源。
<html>
<head>
<title>SOAP JavaScript Client Test</title>
<script type="text/javascript" src="jquery-2.1.1.min.js" ></script>
<script type="text/javascript" >
    function fnc_soap() {
        var request = 
        '<?xml version="1.0" encoding="utf-8"?> ' +
        '<soap12:Envelope ' +
        'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
        'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
        'xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" ' +
        'soap12:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> ' +
            '<soap12:Body> ' +
                '<CelsiusToFahrenheit xmlns="http://www.w3schools.com/webservices/"> ' +
                    '<Celsius>37</Celsius> ' +
                '</CelsiusToFahrenheit> ' +
            '</soap12:Body> ' +
        '</soap12:Envelope>';

        var url = "http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit";
        jQuery.ajax({
            type: "POST",
            url: url,
            data: request,
            dataType: "xml",
            crossDomain: true,
            processData: true,
            contentType: "text/xml; charset=\"utf-8\"",
            xhrFields: {
                withCredentials: true
            },
            beforeSend: function(xhr) {
                // xhr.setRequestHeader('Access-Control-Allow-Methods', 'OPTIONS, TRACE, GET, HEAD, POST');
                xhr.withCredentials = true;
            },
            headers: {
                SOAPAction: "http://www.w3schools.com/webservices/CelsiusToFahrenheit"
            },
            success: function (msg) {
                alert("Works!");
            },
            error: function (msg) {
                alert("Failed: " + msg.status + ": " + msg.statusText);
            }
        });
    }
</script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Soap" onclick="fnc_soap();" ></input>
        </div>
    </form>
</body>
<html>