1. 创建新的 XMLHttpRequest 对象(Ajax 应用程序的核心):

    <script language="javascript" type="text/javascript">
    var xmlHttp = new XMLHttpRequest();
    </script>
  2. 用 JavaScript 代码捕获和设置字段值
    //获取 id 值为 first_name 的表单域
    var name = document.getElementById('first_name').value; //修改 id 值为 test 的表单域的值
    document.getElementById('test').value = response[0];

      

  3. 在 Microsoft 浏览器上创建 XMLHttpRequest 对象
    var xmlHttp = false;
    try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
    xmlHttp = false;
    }
    }

      

  4. 以支持多种浏览器的方式创建 XMLHttpRequest 对象
    /* Create a new XMLHttpRequest object to talk to the Web server */
    var xmlHttp = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    try {
    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e2) {
    xmlHttp = false;
    }
    }
    @end @*/ if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
    }

      

  5. 开始工作:发送Ajax请求
    function callServer() {
    // Get the city and state from the web form
    var city = document.getElementById("city").value;
    var state = document.getElementById("state").value; // Build the URL to connect to
    var url = "/scripts/getZipCode.php?city=" + escape(city) + "&state=" + escape(state); // Open a connection to the server
    xmlHttp.open("GET", url, true); // Setup a function for the server to run when it's done
    xmlHttp.onreadystatechange = updatePage; // Send the request
    xmlHttp.send(null);
    }

      

最新文章

  1. hdu 1398 Square Coins (母函数)
  2. 说说设计模式~桥梁模式(Bridge)
  3. Linux Shell系列教程之(十六) Shell输入输出重定向
  4. label WordWrap
  5. javascript第十一课,string对象
  6. Access之C#连接Access
  7. windows下npm scripts不能执行的问题
  8. Effective Java 之 --- 用私有构造器或者枚举类型强化Singleton属性
  9. 不安装oracle客户端连接oracle数据库
  10. SSH通过SSH代理连接到内网机器
  11. 小程序通过 url 向内嵌 H5 传参注意事项
  12. css 效果之转换
  13. vs远程调试 转http://www.cnblogs.com/magicchaiy/archive/2013/05/28/3088274.html
  14. 算法之LOWB三人组之选择排序
  15. iOS 字典转json字符串
  16. sendfile Linux函数
  17. Java IO流中的flush()
  18. ZOJ - 3216:Compositions (DP&amp;矩阵乘法&amp;快速幂)
  19. spark 都用了哪些开源东东
  20. Servlet类源码说明

热门文章

  1. 《JAVA与模式》之观察者模式
  2. ASP.NET Forms 身份验证
  3. Java 解决约瑟夫问题
  4. c#生成二维码
  5. linux 命令01
  6. Axure RP 7.0注册码
  7. ubuntu系统theano和keras的安装
  8. java常用工具
  9. [每日一记] Python报错 综述
  10. qlikview 扩展插件制作教程-EchartsGeoMap