JQuery AJAX 使用 SOAP Web 服务 [英] JQuery AJAX Consume SOAP Web Service
问题描述
我一直在试验和尝试学习 JQuery,使用 AJAX 来使用我前段时间编写的 SOAP Web 服务.以下是我正在使用的代码:
<form method="post" action=""><div><input type="button" value="Call Web Service" onclick="CallService(); return false;"/>
</表单>
目前,在 Web 服务中调用的方法返回包含类别代码和类别描述的类别系列数组.由于该方法返回 XML,因此我相应地设置了 ajax 查询.但是,当我运行该应用程序时,我收到一个错误"警告框 - 我确定是什么导致了问题.我知道 Web 服务有效,我编写的其他 .NET Web 应用程序每天都会调用它数百次.
任何帮助将不胜感激.
谢谢,
尝试设置 processData: false
标志.这个标志默认是 true
,我猜 jQuery 是 converting 你的XML 到字符串.
$.ajax({网址:webServiceURL,类型:POST",数据类型:xml",数据:soapMessage,过程数据:假,contentType: "text/xml; charset="utf-8"",成功:OnSuccess,错误:OnError});
I have been experimenting and trying to learn JQuery, using AJAX to consume a SOAP web service I had written some time ago. Below is the code I am using:
<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>
Currently, the method being called in the web service returns an array of category families that contain a category code and a category description. Since the method returns XML, I set the ajax query accordingly. However, when I run the app, I get an 'error' alert box - I am sure what would be causing the problem. I know the web service works, it's called several hundred times a day by other .NET web apps that I've written.
Any help would be greatly appreciated.
Thanks,
Try setting processData: false
flag. This flag is true
by default and I guess jQuery is converting your XML to string.
$.ajax({
url: webServiceURL,
type: "POST",
dataType: "xml",
data: soapMessage,
processData: false,
contentType: "text/xml; charset="utf-8"",
success: OnSuccess,
error: OnError
});
这篇关于JQuery AJAX 使用 SOAP Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!