国产探花免费观看_亚洲丰满少妇自慰呻吟_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的時候用的比較多. 具體沒仔細研究.
    還望有其他更簡單方法的同學互相交流下~

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大邑县| 瓦房店市| 湘西| 维西| 大兴区| 星座| 贵阳市| 大渡口区| 定结县| 丘北县| 晋城| 桂东县| 迁西县| 阜平县| 搜索| 永清县| 吴忠市| 扶风县| 叙永县| 四平市| 乌恰县| 石城县| 西畴县| 桐梓县| 筠连县| 措勤县| 旅游| 安国市| 阿尔山市| 邹城市| 伊吾县| 小金县| 漠河县| 澳门| 东兰县| 宜兴市| 巴青县| 综艺| 嫩江县| 怀宁县| 黄冈市|