我一直在尝试学习JQuery,使用AJAX消费我之前编写的SOAP Web服务。以下是我正在使用的代码:
<script type="text/javascript">
var webServiceURL = 'http://local_server_name/baanws/dataservice.asmx?op=GetAllCategoryFamilies';
var soapMessage = '<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:Body><GetAllCategoryFamilies xmlns="http://tempuri.org/" /></soap12:Body></soap12:Envelope';
function CallService()
{
$.ajax({
url: webServiceURL,
type: "POST",
dataType: "xml",
data: soapMessage,
contentType: "text/xml; charset=\"utf-8\"",
success: OnSuccess,
error: OnError
});
return false;
}
function OnSuccess(data, status)
{
alert(data.d);
}
function OnError(request, status, error)
{
alert('error');
}
$(document).ready(function() {
jQuery.support.cors = true;
});
</script>
<form method="post" action="">
<div>
<input type="button" value="Call Web Service" onclick="CallService(); return false;" />
</div>
</form>
目前,Web服务调用的方法返回一个包含类别代码和类别描述的类别族数组。由于该方法返回XML,我根据它设置了Ajax查询。然而,当我运行应用程序时,我会收到一个“错误”警告框,我不确定是什么原因导致的。我知道Web服务可以正常工作,因为我编写的其他.NET Web应用程序每天都会调用它数百次。
非常感谢您的任何帮助。
谢谢,