Home > Web Front-end > JS Tutorial > body text

JavaScript uses JQuery to call server-side method sample code_javascript skills

WBOY
Release: 2016-05-16 16:37:33
Original
1178 people have browsed it

Prepare the server-side method

[System.Web.Services.WebMethod]
public static string VeryUserName(string name)
{
string rtn = "恭喜,此帐号还没有注册,你可以使用。";

if (name == "")
rtn = "请填写一个注册帐号。";

if (name == "Insus.NET")
rtn = "此用户已经注册,请使用另外帐号。"; 

return rtn;
}
Copy after login

HTML code:

<asp:TextBox ID="TextBoxAccount" runat="server"></asp:TextBox><br />
<input id="btnrReg" type="button" value="注册" onclick="VeryRegAccount()" />
Copy after login

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template