我一直在尝试和尝试学习
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查询.但是,当我运行应用程序时,我会收到一个“错误”警告框 – 我确定会导致问题.我知道网络服务的工作原理,每天被我写的其他.NET网络应用程序称为几百次.
任何帮助将不胜感激.
谢谢,
解决方法
尝试设置processData:false标志.这个标志在默认情况下是真的,我猜jQuery是
converting你的XML字符串.
$.ajax({
url: webServiceURL,processData: false,error: OnError
});