国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 編程設計 > 正文

Asp.net中用 AJAX調用后臺靜態的方法總結

2020-07-14 13:37:47
字體:
來源:轉載
供稿:網友

從客戶端調用后臺靜態方法
    1.Ajax Library方式
    C#代碼:
    [WebMethod]
    public static DateTime GetCurrentTime(string str)
    {
        return DateTime.Now;
    }
    JS代碼:
    <form id="form1" runat="server">
    <script language=javascript type="text/javascript">
        function GetCurrentTime1() {
            PageMethods.GetCurrentTime('NewEgg ajax training', CheckIsSuccess);
        }
        function CheckIsSuccess(result) {
            alert(result);
        }
     </script>
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        </asp:ScriptManager>
        <input id="Button1" type="button" value="客戶端控件調用服務器端的方法" onclick="GetCurrentTime1()" />
    </div>
    </form>
    說明:
    C#方法必須加 "[WebMethod]"
    前臺頁面必須使用引用 服務器控件
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    調用方法: PageMethods.后臺方法名(參數[,參數....], 成功后調用的方法名);
Ajax Library
image

image2. jQuery方式    C#代碼:
    [WebMethod]
    public static string ABC(string ABC)
    {
        return ABC;
    }
    JS代碼:
    $().ready(
            function() {
                $("#AjaxDemo").click(function() {
                    $.ajax({
                        type: "POST",
                        url: "Default.aspx/ABC",
                        data: "{'ABC':'test'}",
                        contentType: "application/json; charset=utf-8",
                        success: function(msg) {alert(msg); }
                    })
                })
            }
        )
    說明: 必須引用jQuery庫文件.
    3. 還有一種好像是要引用AJAX.dll文件的. 在后臺注冊前臺方法. 這個好像在.net2.0的時候用的比較多. 具體沒仔細研究.
    還望有其他更簡單方法的同學互相交流下~

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 方山县| 东乡族自治县| 龙胜| 梁平县| 临泉县| 普陀区| 建瓯市| 原阳县| 青浦区| 衡山县| 西和县| 龙游县| 定西市| 齐河县| 深圳市| 漯河市| 呼和浩特市| 澎湖县| 松原市| 吉隆县| 武穴市| 汪清县| 台南县| 恩施市| 镇远县| 安溪县| 城口县| 广南县| 阿瓦提县| 信丰县| 南康市| 宜宾市| 聂拉木县| 安泽县| 满洲里市| 土默特左旗| 景谷| 梁河县| 宁化县| 台南县| 海盐县|