zoukankan      html  css  js  c++  java
  • 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;
                }
    
            })
    

      

  • 相关阅读:
    告别零码软件
    win+mingw+libxml2试用笔记
    beacon with java 1.7 on fedora
    mininet指令详解
    java Socket完美实例
    gnome3 下 qt 应用极其丑陋的解决方案
    org.apache.log4j Class Level
    Mac如何修改文本文件编码
    unity性能优化相关
    平面图判定
  • 原文地址:https://www.cnblogs.com/tony-brook/p/7874195.html
Copyright © 2011-2022 走看看