【问题标题】:Call webmethod in ascx page using jquery ajax使用 jquery ajax 在 ascx 页面中调用 webmethod
【发布时间】:2016-08-15 16:39:29
【问题描述】:

出于某些原因,我想从 jquery ajax 调用 ascx 页面中的 webmethod。

.ascx 页面

function StartProcessing() {
    ShowProgress();
    $.ajax({
        type: "POST",
        url: "ImportExcel.ascx/btnProcessing_Click",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            alert('hi');

        },
        error: function (data) {
            alert('error');
        }
    });
}

我在 ascx.cs 页面中的 webmethod:

[WebMethod]
    public static void btnProcess_Click(object sender, EventArgs e)
    {
       //code which processes records in excel file
    }

请提出一些方法来从 jquery ajax 调用 ascx 中的 webmethod

谢谢。

【问题讨论】:

    标签: c# jquery ajax webmethod ascx


    【解决方案1】:

    你的方法必须像这样是静态的:

    [WebMethod]
    public static void ProcessExcelRecords()
    {
       //code which processes records in excel file
    }
    

    【讨论】:

    • 马克,我已经编辑了我的 web 方法,但我需要从 jquery ajax 调用它。
    猜你喜欢
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多