Jquery 调用asp.net ajax (web service/static page method)的示例(一)---简单参数

示例一(无参数的情况) :

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "WebService.asmx/WebMethodName",
    data: "{}",        //当被调用的page method 或则 web service 的方法是无参情况时候,需要传入空的json  对象
    dataType: "json"
});


示例二(简单参数的情况) :

    $.ajax({
            type: "POST",
            url: "../Services/UCRender.asmx/GetControl",
            data: "{'path':'~/UserControls/RSSReaderControl.ascx'}",     
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                $('#RSSContent').removeClass('loading');
                $('#RSSContent').html(msg.d);
            }
        });
    }


对应的service 方法如下:

/// <summary>
/// Summary description for UCRender
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class UCRender : System.Web.Services.WebService
{
     [WebMethod]
    public string GetControl(string path)
    {
        Page page = new Page();
        UserControl ctl = (UserControl)page.LoadControl(path);
        page.Controls.Add(ctl);
        StringWriter writer = new StringWriter();
        HttpContext.Current.Server.Execute(page, writer, false);
        return writer.ToString();
        }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值