【发布时间】:2014-03-05 02:16:43
【问题描述】:
我希望有人能对此有所了解。我是使用 SOAP 服务的新手,并且很难理解为什么我无法在我的 ajax 调用中得到响应。
请求和响应在 SOAPui 中完美运行,只是在浏览器的 ajax 中不行。我也不确定如何检查响应是否有效。
另外,值得指出的是,如果我改变了
contentType: "application/soap+xml; charset=utf-8", 至 内容类型:“文本/xml”,
它总是给出错误。
SOAP 响应
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<vcr:ValidResponse xmlns:vcr="http://url/central-register">
<vcr:valid>true</vcr:valid>
</vcr:ValidResponse>
</soapenv:Body>
</soapenv:Envelope>
AJAX
<script type="text/javascript">
var soapMessage = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cen="http://url/central-register">'+
'<soap:Header/>'+
'<soap:Body>'+
'<cen:ValidRequest>'+
'<cen:personIdentity>'+
'<cen:Id>32342</cen:Id>'+
'<cen:surname>SMITH</cen:surname>'+
'<cen:dateOfBirth>1943-02-14</cen:dateOfBirth>'+
'</cen:personIdentity>'+
'<cen:Credentials>'+
'<cen:Username>CGWSV02</cen:Username>'+
'<cen:Password>February2014</cen:Password>'+
'</cen:Credentials>'+
'</cen:ValidRequest>'+
'</soap:Body>'+
'</soap:Envelope>';
function CallService()
{
$.ajax({
url: "https://www.url-to-soap-service/",
type: "POST",
dataType: "xml",
contentType: "application/soap+xml; charset=utf-8",
data: soapMessage,
success: OnSuccess,
error: OnError
});
return false;
}
function OnSuccess(data, status)
{
alert(data);
}
function OnError(request, status, error)
{
alert('error');
}
$(document).ready(function() {
jQuery.support.cors = true;
});
</script>
<form method="post" action="">
<input type="submit" value="SUBMIT" onclick="CallService(); return false;" />
</form>
【问题讨论】:
-
您是否在您的肥皂中启用了 ajax?
-
我没有创建 SOAP 服务本身所以没有。
-
我猜 SOAP 服务位于另一个域中,并且 AJAX 请求在同源策略下被阻止...我对跨域 AJAX 调用没有经验。
标签: jquery ajax web-services soap