【问题标题】:When calling a asmx service via jQuery, how to pass arguments?通过 jQuery 调用 asmx 服务时,如何传递参数?
【发布时间】:2010-05-10 20:46:40
【问题描述】:

如何传递我的服务端点参数? (本例中的页面大小)

我的 .asmx 服务方法如下:

 [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public List<Object> GetData(int pageSize)
    {

    }

当我通过 jQuery 调用它时:

$.ajax({
        type: "POST",
        url: "test.asmx/test123",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {

        },
        error: function(msg) {

        }
    });

【问题讨论】:

    标签: c# asp.net web-services asmx


    【解决方案1】:

    你可以将它作为json传递:

    $.ajax({
        type: "POST",
        url: "test.asmx/test123",
        data: "{'pageSize':'14'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
    
        },
        error: function(msg) {
    
        }
    });
    

    【讨论】:

      【解决方案2】:

      你需要构建一个json对象:

      data: {pageSize: 1}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-03-26
        • 1970-01-01
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        • 2023-02-05
        • 1970-01-01
        相关资源
        最近更新 更多