ajax将数据发送到后面的代码不工作

时间:2018-03-12 18:17:50

标签: jquery .net ajax

请让我知道我在这里做错了什么?

 $.ajax({
    type: "POST",
    url: "index.aspx/check_phone_no_server",
    data: "{'Email':'" + $('#phoneno').val() + "'}",
    async: false,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        alert(response.d);
        if (response.d != "0")
            alert("1 is heere");
        else {
            alert("0 is heere");
        }
    }
});




[System.Web.Services.WebMethod]
    public static string check_phone_no_server(string Email)
    {
        //index a = new index();
        //return a.check_phone_no();
        return Email.ToString();
    }

1 个答案:

答案 0 :(得分:0)

您只需将数据作为Object传递,而不是String

$.ajax({
    type: "POST",
    url: "index.aspx/check_phone_no_server",
    data: {
        Email: $('#phoneno').val() //will probably not be phoneno
    },
    async: false,
    dataType: "json",
    success: function (response) {
        alert(response.d);
        if (response.d != "0")
            alert("1 is heere");
        else {
            alert("0 is heere");
        }
    }
});