如何使用jQuery来调用ASP.NET web服务? [英] How to use jQuery to call an ASP.NET web service?
问题描述
我试图使用jQuery来得到一个ASP.NET Web服务(SharePoint Server 2007的lists.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.
推荐答案
我用这个方法作为包装,这样我可以发送参数。还利用变量的方法的顶部允许它在一个较高的比率被最小化,并允许一些code重用如果使多个类似的呼叫。
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屋!