zoukankan      html  css  js  c++  java
  • 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();
    }




  • 相关阅读:
    ByteBuffer使用实例
    Fiddler抓包显示请求时延
    手机wifi连上Fiddler后无网络问题解决
    git
    git
    Autofac使用
    Redis实战
    Redis实战
    Redis实战
    Redis实战
  • 原文地址:https://www.cnblogs.com/yaoshan/p/2876296.html
Copyright © 2011-2022 走看看