• 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;
                }
    
            })
    

      

  • 相关阅读:
    stark
    MySQL与JDBC
    存储过程/视图/触发器
    MyCat部署运行(Windows环境)与使用步骤详解
    常用单词总结
    表单校验---validation检验
    jQuery简介
    javascript简单介绍
    HTML&&CSS
    消息队列Java的简单实现
  • 原文地址:https://www.cnblogs.com/tony-brook/p/7874195.html
Copyright © 2020-2023  润新知