Prepare the server-side method
[System.Web.Services.WebMethod] public static string Veryusername (string name) { string rtn = "Congratulations, this account has not yet been registered and you can use it. "; if (name = = "") Rtn = "Please fill in a registered account. "; if (name = = "Insus.net") RTN = "This user is already registered, please use another account." "; return RTN; }
HTML code: <asp:textbox id= "Textboxaccount" runat= "server" ></asp:textbox><br/> <input ID= " Btnrreg "type=" button "value=" registers "onclick=" Veryregaccount () "/>javascript script:
[JavaScript]View Plaincopy
- View Code
- <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>
JavaScript calls server-side method with jquery