我试图用jquery.ajax调用我的web服务。
jQuery.support.cors = true;
$.ajax({
type: 'POST',
url: wsUrl,
contentType: "text/xml; charset=utf-8",
dataType: "xml",
cache: false,
crossDomain: true,
data: soapRequest,
success: reqSuccess,
error: reqError
});
我得到“拒绝访问” - 错误和状态/ readyState 0。
如果我使用SoapUI向我的网络服务提出请求,它的效果非常好。
答案 0 :(得分:1)
在发出SOAP请求时,请确保将processData
设置为false
以防止jQuery将您的XML请求转换为字符串。
$.ajax({
type: 'POST',
url: wsUrl,
contentType: "text/xml; charset=utf-8",
dataType: "xml",
cache: false,
crossDomain: true,
data: soapRequest,
processData: false,
success: reqSuccess,
error: reqError
});
来自文档:http://api.jquery.com/jQuery.ajax/
processData (default: true)
Type: Boolean
By default, data passed in to the data option as an object (technically, anything
other than a string) will be processed and transformed into a query string, fitting
to the default content-type "application/x-www-form-urlencoded". If you want to send
a DOMDocument, or other non-processed data, set this option to false.