如何传递参数到asp.net web服务并返回xml
How to pass on a parameter to asp.net web service and return xml?
目前我有一个按钮,用jQuery/AJAX从SharePoint列表中搜索所有客户,我的web服务返回一个XML字符串。然后用XML中的数据填充下拉列表。
我知道我想传递一个参数(客户名)的搜索功能,我可以从SharePoint列表返回我想要的,但我的AJAX调用返回错误(parseerror)。
获得所有客户(有效):
$.ajax({
type: "GET",
url: "SynchroniseCustomers.asmx/GetAllCustomers",
dataType: "text/xml",
error: function (xhr, status) {
hideLoading();
},
beforeSend: function () {
showLoading("customers");
},
success: function (xml) {
hideLoading();
populatecustomerDropdownList($(xml).text());
}
});
我不确定如何继续下去,但我试过了
var customer = CustomerName;
$.ajax({
type: "GET",
data: { CustomerName: JSON.stringify(customer) },
url: "SynchroniseCustomers.asmx/GetCustomerByName",
dataType: "json",
error: function (xhr, status) {
hideLoading();
alert(xhr + " " + status);
},
beforeSend: function () {
showLoading("Customers");
},
success: function (xml) {
hideLoading();
populateCustomerDropdownList($(xml).text());
}
});
谁能告诉我该怎么做吗?
如果指定返回数据类型为JSON,则应该是XML:
dataType: "xml"
populatecustomerDropdownList($(xml).text());
当你做$(xml)
时,你访问你的结构就像HTML一样,所以例如,如果结构是:
<?xml version="1.0" encoding="utf-8" ?>
<RecentTutorials>
<Tutorial author="The Reddest">
<Title>Silverlight and the Netflix API</Title>
<Categories>
<Category>Tutorials</Category>
<Category>Silverlight 2.0</Category>
<Category>Silverlight</Category>
<Category>C#</Category>
<Category>XAML</Category>
</Categories>
<Date>1/13/2009</Date>
</Tutorial>
jQuery: success: function(xml) {
$(xml).find("Tutorial").each(function()
{
$("#output").append($(this).attr("author") + "<br />");
});
}
我不知道从web服务返回XML数据,但可以帮助您发送位。
如果customer变量只是一个简单的字符串,则使用
data: { "CustomerName": customer },
如果客户变量是复杂类型,则使用
data: { "CustomerName": JSON.stringify(customer) },
有关传递复杂类型的更多信息,请阅读Dave Ward撰写的文章。
相关文章:
- 监视函数从服务返回不起作用,但作用域函数起作用
- 为什么Angularjs服务返回的是字符数组而不是对象数组
- SailsJS:如何从服务返回值
- 我怎么能在Angular JS中等待,直到我的web服务返回
- 如何在公共js模块中从web服务返回数据
- 从服务返回值时$scope控制器的变量是未定义的
- 从角度服务返回空值的变量
- ajax调用wcf服务返回错误
- 在测试之前,需要量角器等待服务返回
- 从 Web 服务返回单个 json 对象的数组
- Web服务返回给javascript的值是未定义的
- 有没有办法等到方向服务返回结果
- 从 Angular 服务返回 http 数据
- Javascript 从 Web 服务返回文件
- 如何在角度 js 中从服务返回值
- 从使用 $resource 的服务返回新对象
- 节点脚本需要向调用它的 Angular 服务返回成功/失败
- 保存服务返回的PDF
- 如何在javascript或jquery中访问Web服务返回的JSON中的数据
- 模拟服务返回promise:无法读取未定义的属性