ASP.NET Webforms - Calling a C# method with AJAX

前端 未结 3 1328
-上瘾入骨i
-上瘾入骨i 2020-12-22 09:13

I\'ve an asp button on an aspx :



        
3条回答
  •  春和景丽
    2020-12-22 09:44

    Your method must be static and decorated with [WebMethod] as below, why should make it static and decorate with [WebMethod]?

    [WebMethod]
    public static void GetReport()
    {
        // Your code here
    }
    
    $.ajax({
        type: "POST",
        url: "Selection.aspx/GetReport",
        data: JSON.stringify({ parametername : "Parameter Value" }),
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function()
        {
            alert('success');
        },
        error: function()
        {
           alert('error');
        }
    });
    

提交回复
热议问题