zoukankan      html  css  js  c++  java
  • ajax(xmlHttpRequest对象)的运行原理固定模式

    发出请求

    您已经有了一个崭新的 XMLHttpRequest 对象,现在让它干点活儿吧。首先需要一个 Web 页面能够调用的 JavaScript 方法(比如当用户输入文本或者从菜单中选择一项时)。接下来就是在所有 Ajax 应用程序中基本都雷同的流程:

    1、从 Web 表单中获取需要的数据。 
    2、建立要连接的 URL。 
    3、打开到服务器的连接。 
    4、设置服务器在完成后要运行的函数。 
    5、发送请求。

    清单 5 中的示例 Ajax 方法就是按照这个顺序组织的:

    清单 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;
      // Only go on if there are values for both fields
      if ((city == null) || (city == "")) return;
      if ((state == null) || (state == "")) return;

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

  • 相关阅读:
    Linux防火墙白名单设置
    postgre级联更新
    postgre查询表和记录数,查表字段
    PostgreSQL中的 时间格式转化常识
    android 阿里云oss上传
    android studio connot resolve
    Mysql 优化,慢查询
    Docker 容器更新,打包,上传到阿里云
    Mysql 替换字段的一部分内容
    Docker 安装Nginx
  • 原文地址:https://www.cnblogs.com/zlzlzl1993/p/3316941.html
Copyright © 2011-2022 走看看