• 使用 ajax 异步调用数据


    ajax 脚本

    <script type="text/javascript" >
           function show(page)
            {
              var xmlhttp;
              try
              {
                xmlhttp=new XMLHttpRequest();
              }
              catch(e)
              {
                 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
              xmlhttp.onreadystatechange=function()
              {
              if (xmlhttp.readyState==4)
              {
                if (xmlhttp.status==200)
                {
                    var data=xmlhttp.responseText;        
                    document.getElementById("divInfor").innerHTML=unescape(data);   //divInfor 需要显示异步调用数据的地方
                }
              }
            }
                xmlhttp.open("post", "showInfor.aspx", true);    //showInfor.aspx 写异步调用数据的地方
                xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
                xmlhttp.send("lx=all&page="+escape(page));       //需要传递的参数
            }    
        </script>

    HTML页面

    <form id="form1" runat="server">
        <div>
          如何使用ajax来实现异步调用数据
        </div>
        <div><input type="button"  value="显示ajax内容"  onclick="show('5')"  /></div>
        <br />
        <div id="divInfor"></div>
    </form>

    异步调用页面代码   showInfor.aspx

    public partial class showInfor : System.Web.UI.Page
    {
        protected string strType = "";
        protected string strPage = "";
    
        protected void Page_Load(object sender, EventArgs e)
        {
            strType = Convert.ToString(Request.Form["lx"]);              //参数调用是用Request.Form  而不是Request.QueryString 
            strPage = Convert.ToString(Request.Form["page"]);
    
            Response.Write("类型为:" + strType + "<br /> 页面为:" + strPage);
        }
    }
  • 相关阅读:
    c++的stack容器
    c++的deque容器
    Vector容器
    stl的string
    MATLAB 矩阵操作(三)
    MATLAB 矩阵操作(二)
    智慧树刷课
    MATLAB 将 n 美分转换成 25、10、5 和 1 美分的硬币总共有多少种转换方法?编写一个函数,传入参数 n,输出转换的种类
    MATLAB 图像处理于数字化之简单图像加密算法
    Python 第三方库的安装
  • 原文地址:https://www.cnblogs.com/enamorbreeze/p/6283664.html
Copyright © 2020-2023  润新知