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" οnclick="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
相关资源:asp.net jquery ajax所有调用例子