zoukankan      html  css  js  c++  java
  • js之ajax实例

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>js中的Ajax经典示例</title>
        <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
        <script type="text/javascript">
        
          function ajax() {
    
              //先声明一个异步请求对象
              var xmlHttpReg = null;
              if (window.ActiveXObject) {//如果是IE
    
                  xmlHttpReg = new ActiveXObject("Microsoft.XMLHTTP");
    
              } else if (window.XMLHttpRequest) {
    
                  xmlHttpReg = new XMLHttpRequest(); //实例化一个xmlHttpReg
              }
    
              //如果实例化成功,就调用open()方法,就开始准备向服务器发送请求
              if (xmlHttpReg != null) {
                  xmlHttpReg.open("get", "About.aspx", true);1
                   xmlHttpReg.send(null);
                  xmlHttpReg.onreadystatechange = doResult; //设置回调函数
    
              }
    
              //回调函数
              //一旦readyState的值改变,将会调用这个函数,readyState=4表示完成相应
    
              //设定函数doResult()
              function doResult() {
              
                  if (xmlHttpReg.readyState == 4) {//4代表执行完成
                     
                     
                      if (xmlHttpReg.status == 200) {//200代表执行成功
                          //将xmlHttpReg.responseText的值赋给ID为resText的元素
                          document.getElementById("resText").innerHTML = xmlHttpReg.responseText;
                          
    
                      }
                  }
    
              }
            
    
          }
         </script>
    </head>
    <body>
          
          <div id="resText"></div>
          <form method=get action="">
            <input type="button" value="小胡子"  onclick="ajax();"/>
          </form>
    </body>
    </html>
  • 相关阅读:
    web.py的input获取问题
    python unicode和 utf8字符串比较
    python default encoding
    linux flash player的问题
    centos 支持 ntfs格式
    学习jqueryjquery中的show()和hide()
    字符串等长分割
    类加载器分类
    类加载器子系统
    70道HR的面试题
  • 原文地址:https://www.cnblogs.com/youbiao/p/7068244.html
Copyright © 2011-2022 走看看