0

I'm calling a SOAP WebService from JavaScript. In IE my code works, but on Firefox the error function is called with textStatus = "error", xhr.status = 0 and errorThrown empty. I tried different answers, found on SO, but couldn't solve the problem.

    jQuery.support.cors = true;
    jQuery.ajax({
        url: serviceUrl,
        beforeSend: function (xhr) {
            xhr.setRequestHeader("SOAPAction", soapAction);
        },
        type: "POST",
        dataType: "xml",
        data: soap,
        success: function(data, textStatus, jqXHR ) {
            // report success
            success.style.display='block';
        },
        error: function (jqXHR, textStatus, errorThrown) {
            // report error
            fail.style.display='block';
            alert(textStatus + ": " + jqXHR.status + " / " + errorThrown);
        },
        contentType: "text/xml; charset=utf-8"
    });

Browserversions: IE 9, Firefox 23.0.1

4

1 回答 1

0

这是因为同源政策。您不能使用 ajax 调用外部站点。如果你真的要使用,你必须使用 JSONP。或者您可以为此使用服务器端代理。意思是,在服务器端调用外部站点并对那个 web 服务进行 ajax 调用。

于 2013-09-05T11:35:55.477 回答