jquery ajax asp.net

function yanzhengma() {
var msgma = $("#txtma").val();
$.ajax({

type: "Post",
url: "WebForm3.aspx/RequestMethod2",
data: "{'msg':'" + msgma + "'}",
contentType: "application/json;charset=utf-8", // 这句可不要忘了。
dataType: "json",
success: function (res) {
alert(res.d); // 注意有个d,至于为什么通过chrome看响应吧,O(∩_∩)O。
},
error: function (xmlReq, err, c) {
alert(err);
}
});
}

<input type ="text" id="txtma" />
<input type ="button" onclick="yanzhengma()" value="确定" />

[WebMethod]
public static string RequestMethod2(string msg)
{
try
{
string ma = HttpContext.Current.Session["ma"].ToString();
if (ma == msg)
{
return "yes";
}
else
{
return "no";
}
}
catch
{
return "您还没有发送短信验证码,或已过期";
}
}

原文地址:https://www.cnblogs.com/waiwai1015/p/4705060.html