JavaScript用JQueryコールサーバ側メソッド

2086 ワード

   Server    
[System.Web.Services.WebMethod]

    public static string VeryUserName(string name)

    {

        string rtn = "  ,        ,     。";



        if (name == "")

            rtn = "         。";

        

        if (name == "Insus.NET")

            rtn = "       ,       。";        



        return rtn;

    }
 HTML  :<asp:TextBox ID="TextBoxAccount" runat="server"></asp:TextBox><br />

            <input id="btnrReg" type="button" value="  " onclick="VeryRegAccount()" />

Javascript  :

[javascript]
view plain
copy
View Code   
  •   

  •   
  •       

  •         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);  
  •         }  

  •