亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        JS AJAX前臺如何給后臺類的函數(shù)傳遞參數(shù)

        字號:


            這篇文章主要介紹了JS AJAX前臺給后臺類的函數(shù)傳遞參數(shù)的方法,下面有個不錯的示例,需要的朋友可以參考下
            將普通頁面的方法公布為WebMethod,以Javascript形式訪問。
            1 方法要public static修飾,返回類型最好是string。
            2 方法前添加[WebMethod] 特性。
            3 Client端訪問時要使用Post方法,和Json作為數(shù)據(jù)形式進行交互。否則會整頁HTML返回。
            4 在jQuery訪問時,回調中的data.d才時真正的返回內(nèi)容。
            5 訪問URL為: http://abc.com/abc.aspx/GetTime 如有個GetTime的公共靜態(tài)方法。
            [WebMethod]
            2
            public
            static
            string
            GetTime()
            3
            {
            4
            return
            DateTime.Now.ToString(
            "yyyy-MM-dd HH:mm:ss"
            );
            5
            }
            ---------------
            腳本(以jQuery為例調用)
            $.ajax({
            2
            url:url,
            3
            method:
            "post"
            ,
            4
            dataType:
            "json"
            ,
            5
            contentType:
            "application/json; charset=UTF-8"
            ,
            6
            success:
            function
            (data){
            7
            $(
            "#id"
            ).html(data.d);
            //見第3點
            8
            }
            9
            });