JQuery的AJAX消费SOAP的Web服务 [英] JQuery AJAX Consume SOAP Web Service
问题描述
我一直在尝试和努力学习JQuery的,使用AJAX来消耗我写了前段时间的SOAP Web服务。下面是code我使用的:
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>
目前,被称为在Web服务中的方法返回类别的家庭包含一类code和一个类别描述的数组。由于该方法返回的XML,我相应地设置了ajax查询。然而,当我运行的应用程序,我得到一个错误提示框 - 我相信会是什么引起的问题。我知道web服务工作,它是由我写其他.NET Web应用程序名为每天几百次。
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.
任何帮助将是很大的AP preciated。
Any help would be greatly appreciated.
谢谢
推荐答案
尝试设置过程数据:假
标志。这个标志是真
默认情况下,我想jQuery是转换您的XML字符串。
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屋!