• JavaScript用JQuery呼叫Server端方法


    准备好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 plaincopy
    1. View Code   
    2.   
    3. <script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script>  
    4.     <script type="text/javascript">  
    5.         function VeryRegAccount() {  
    6.             $.ajax({  
    7.                 type: "POST",  
    8.                 url: "Default.aspx/VeryUserName",  
    9.                 data: '{name: "' + $("#<%= TextBoxAccount.ClientID%>")[0].value + '" }',  
    10.                 contentType: "application/json; charset=utf-8",  
    11.                 dataType: "json",  
    12.                 success: OnSuccess,  
    13.                 failure: function (response) {  
    14.                     alert(response.d);  
    15.                 }  
    16.             });  
    17.         }  
    18.         function OnSuccess(response) {  
    19.             alert(response.d);  
    20.         }  
    21.     </script> 
  • 相关阅读:
    springboot缓存-Ehcache
    springboot+spring data jpa 多数据源配置
    vue+element 上传图片控件
    springboot下载文件
    easyPoi导入带图片的excel
    内外网同时使用(宽带内网无线内网)
    mysql 8.0 安装
    搭建一个Vue前端项目
    mybatis反向代理自动生成mapper文件
    【1】idea Live Templates
  • 原文地址:https://www.cnblogs.com/rr163/p/3953889.html
Copyright © 2020-2023  润新知