• 1.XMLHttpRequest:


    1.XMLHttpRequest:
    GET:
    var client = new XMLHttpRequest();
    client.onreadystatechange = handler;
    client.open("GET", "unicorn.xml");
    client.send();

    function handler() {
      if(this.readyState == this.DONE) {
        if(this.status == 200 &&
           this.responseXML != null && this.responseXML.getElementById('test').textContent) {
          // success!
          processData(this.responseXML.getElementById('test').textContent);
          return;
        }
        // something went wrong
        processData(null);
      }
    }
    If you just want to log a message to the server:
    function log(message) {
      var client = new XMLHttpRequest();
      client.open("POST", "/log");
      client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
      client.send(message);
    }

    Or if you want to check the status of a document on the server:

    function fetchStatus(address) {
      var client = new XMLHttpRequest();
      client.onreadystatechange = function() {
        // in case of network errors this might not give reliable results
        if(this.readyState == this.DONE)
          returnStatus(this.status);
      }
      client.open("HEAD", address);
      client.send();
    }




  • 相关阅读:
    vue.js 首屏优化
    ios判断是否有中文
    ios 7新特性
    NSDictionary的分类
    asiHttpRequst 超时代码判断
    ios中layoutsubview何时被调用
    ios中tableview的移动添加删除
    ios发布
    新浪博客中放大图片的做法
    ios中coredata
  • 原文地址:https://www.cnblogs.com/yaoshan/p/2876296.html
Copyright © 2020-2023  润新知