Ajax调用未达到asp.net Web表单页面的功能

时间:2018-07-24 11:29:08

标签: jquery asp.net-ajax webmethod

这是jquery ajax调用函数

    function Press() {           
        var number = $("#num").val();
        $.ajax({
            type: "POST",
            url: "WebForm1.aspx/GetStuffList",
            data: "{ num:' + number + ' }",
            success: function (response) {
                debugger
                alert("Test")
            }
        })
    }

这是我的网络表单页面功能

    [System.Web.Services.WebMethod]
    public static string GetStuffList(string num)
    {

        return num;
    }

问题:

该jquery函数成功命中,但ajax调用未命中webform页面函数。

1 个答案:

答案 0 :(得分:0)

您应该在App_Code / RouteConfig.cs中注释掉一行

settings.AutoRedirectMode = RedirectMode.Permanent;

应该是

//settings.AutoRedirectMode = RedirectMode.Permanent;

您的ajax帖子中的数据也有问题,您应该使用JSON响应:

       $.ajax({
            type: "POST",
            url: "WebForm1.aspx/GetStuffList",
            data: '{num: "' + number + '" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                console.log(response);                
            }
        });

干杯