webform ajax 異步請求



第一種就是對應方法的請求 雖然對應方法 但還是會刷新頁面 webform是基於事件的 每次請求都會出發pageload
<script>
        $(function () {
            $("#btn").click(function () {
                $.ajax({
                    type: "POST",
                    contentType: "application/json",
                    url: "Index.aspx/SayHello",
                    data: null,
                    dataType: "json",
                    success: function (msg) {
                        alert(msg.d);
                    }
                });
            });
        });
    </script>




[System.Web.Services.WebMethod] public static string SayHello() { return "Hello"; }


第二種方法 就是直接請求 pageload
protected void Page_Load(object sender, EventArgs e)
{
  _delWhere = "";
  if (Request["where"] != null)
  {

    _where = Request["where"].ToString();
    BindData(_where);
  }
}

  

 $.ajax({
            url: "BugListnew.aspx?where=" + where,
            type: "Post",
            dataType: "json", //請求到服務器返回的數據類型  
            data: { "where": where },

            success: function(data) {

                var obj = $.parseJSON(data); //這個數據  

                var name = obj.Json[0].UserName;
                var age = obj.Json[0].Age;

                document.getElementById("name").innerHTML = name;
                document.getElementById("age").innerHTML = age;
            }

        })

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM