JavaScript uses the jquery call server side method to implement code and Reference grammar _ practical skills

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.