Insus.net has been learning JavaScript since 2013, the first time using jquery to call the server side of jquery from JavaScript clients.
First Look at the demo of this example:
How to prepare the server side:
Copy Code code as follows:
[System.Web.Services.WebMethod]
public static string Veryusername (string name)
{
String RTN = "Congratulations, this account has not yet registered, you can use." ";
if (name = = "")
RTN = "Please fill in a registered account number." ";
if (name = = "Insus.net")
RTN = "This user is already registered, please use another account number." ";
return RTN;
}
HTML code:
Copy Code code as follows:
Account:
<asp:textbox id= "Textboxaccount" runat= "Server" ></asp:textbox><br/>
<input id= "Btnrreg" type= "button" value= "register" onclick= "Veryregaccount ()"/>
JavaScript script:
Copy Code code as follows:
<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>
refer to the following syntax: