如何使用jQuery来调用ASP.NET web服务? [英] How to use jQuery to call an ASP.NET web service?

查看:122
本文介绍了如何使用jQuery来调用ASP.NET web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆