如何使用 jQuery 调用 ASP.NET Web 服务? [英] How to use jQuery to call an ASP.NET web service?
问题描述
我正在尝试使用 jQuery 从 ASP.NET Web 服务(SharePoint Server 2007 列表.asmx)中获取数据,但任何对 Web 服务的调用都将真正有助于朝着这个方向迈出的第一步.
I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint Server 2007 lists.asmx), but any call to a web service will really help as a first step in that direction.
推荐答案
我将此方法用作包装器,以便我可以发送参数.此外,使用方法顶部的变量可以以更高的比率将其最小化,并在进行多次类似调用时允许一些代码重用.
I use this method as a wrapper so that I can send parameters. Also using the variables in the top of the method allows it to be minimized at a higher ratio and allows for some code reuse if making multiple similar calls.
function InfoByDate(sDate, eDate){
var divToBeWorkedOn = "#AjaxPlaceHolder";
var webMethod = "http://MyWebService/Web.asmx/GetInfoByDates";
var parameters = "{'sDate':'" + sDate + "','eDate':'" + eDate + "'}";
$.ajax({
type: "POST",
url: webMethod,
data: parameters,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$(divToBeWorkedOn).html(msg.d);
},
error: function(e){
$(divToBeWorkedOn).html("Unavailable");
}
});
}
希望能帮到你.
请注意,这需要 3.5 框架来公开可以以这种方式使用的 JSON webmethods.
Please note that this requires the 3.5 framework to expose JSON webmethods that can be consumed in this manner.
这篇关于如何使用 jQuery 调用 ASP.NET Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!