JavaScript用JQuery呼叫Server端方法教程示例代码
程序员文章站
2023-11-03 19:03:22
准备好server端的方法
[system.web.services.webmethod]
public static string veryusername(stri...
准备好server端的方法
[system.web.services.webmethod] public static string veryusername(string name) { string rtn = "恭喜,此帐号还没有注册,你可以使用。"; if (name == "") rtn = "请填写一个注册帐号。"; if (name == "insus.net") rtn = "此用户已经注册,请使用另外帐号。"; return rtn; }
html代码:
<asp:textbox id="textboxaccount" runat="server"></asp:textbox><br /> <input id="btnrreg" type="button" value="注册" onclick="veryregaccount()" />
javascript脚本:
<script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function veryregaccount() { $.ajax({ type: "post", url: "default.aspx/veryusername", data: '{name: "' + $("#<%= textboxaccount.clientid%>")[0].value + '" }', contenttype: "application/json; charset=utf-8", datatype: "json", success: onsuccess, failure: function (response) { alert(response.d); } }); } function onsuccess(response) { alert(response.d); } </script>