JavaScript using jquery Call server-side Method sample code _javascript Tips

Source: Internet
Author: User

How to prepare the server side

[System.Web.Services.WebMethod]
public static string Veryusername (string name)
{
string rtn = "Congratulations, this account is not yet registered, you can use." ";

if (name = = "")
Rtn = "Please fill out a registered account number." ";

if (name = = "Insus.net")
RTN = "This user is already registered, please use a different account number." "; 

return RTN;
}

HTML code:

<asp:textbox id= "Textboxaccount" runat= "Servers" ></asp:textbox><br/> <input ID=
"BtnrReg" Type= "button" value= "register" onclick= "Veryregaccount ()"/>

JavaScript script:

 <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/very UserName ", 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> 
Related Article

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.