JavaScript用JQuery呼叫Server端方法示例代码
准备好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>
相关推荐
hhanbj 2020-11-17
81427005 2020-11-11
nmgxzm00 2020-11-10
ifconfig 2020-10-14
zfszhangyuan 2020-11-16
古叶峰 2020-11-16
一个智障 2020-11-15
jipengx 2020-11-12
xixixi 2020-11-11
游走的豚鼠君 2020-11-10
苗疆三刀的随手记 2020-11-10
Web卓不凡 2020-11-03
小飞侠V 2020-11-02
帕尼尼 2020-10-30
爱读书的旅行者 2020-10-26
帕尼尼 2020-10-23
杏仁技术站 2020-10-23
淼寒儿 2020-10-22