zoukankan      html  css  js  c++  java
  • AJPFX关于VIM的常用快捷键

    Ajax技术的核心是XMLHttpRequest对象(简称XHR),
    var xhr = new XMLHttpRequest();
    function createXHR(){
    if (typeof XMLHttpRequest != "undefined"){
    return new XMLHttpRequest();
    } else if (typeof ActiveXObject != "undefined"){
    if (typeof arguments.callee.activeXString != "string"){
    var versions = [ "MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0",
    "MSXML2.XMLHttp"],
    i, len;
    for (i=0,len=versions.length; i < len; i++){
    try {
    new ActiveXObject(versions[i]);
    arguments.callee.activeXString = versions[i];
    break;
    } catch (ex){
    //跳过
    }
    }
    }
    return new ActiveXObject(arguments.callee.activeXString);
    } else {
    throw new Error("No XHR object available.");
    }
    }
    2.xhr.open("get", "example.txt", false);
    xhr.send(null);
    3.responseText:作为响应主体被返回的文本。
    responseXML:如果响应的内容类是"text/xml"或"application/xml",这个属性中将保 存包含着响应数据的XML DOM 文档。
    4.
    0:未初始化。尚未调用open()方法。
    1:启动。已经调用open()方法,但尚未调用send()方法。
    2:发送。已经调用send()方法,但尚未接收到响应。
    3:接收。已经接收到部分响应数据。
    4:完成。已经接收到全部响应数据,而且已经可以在客户端使用了。
    eg:
    (get请求)var xhr = createXHR();
    xhr.onreadystatechange = function(){
    if (xhr.readyState == 4){
    if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304){
    alert(xhr.responseText);
    } else {
    alert("Request was unsuccessful: " + xhr.status);
    }
    }
    };
    xhr.open("get", "example.txt", true);
    xhr.send(null);
    (post请求)function submitData(){
    var xhr = createXHR();
    xhr.onreadystatechange = function(){
    if (xhr.readyState == 4){
    if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304){
    alert(xhr.responseText);
    } else {
    alert("Request was unsuccessful: " + xhr.status);
    }
    }
    };
    xhr.open("post", "postexample.php", true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    var form = document.getElementById("user-info");
    xhr.send(serialize(form));
    }

    转载于:https://blog.51cto.com/14314113/2398564

  • 相关阅读:
    Partial Tree(DP)
    Petya and Array (权值线段树+逆序对)
    Tomb Raider(暴力模拟)
    Tunnel Warfare (区间合并|最大值最小值巧妙方法)
    Array Product(模拟)
    Saving Tang Monk II(bfs+优先队列)
    Water Tree(树链剖分+dfs时间戳)
    Tree(树链剖分+线段树延迟标记)
    Jiu Yuan Wants to Eat(树链剖分+线段树延迟标记)
    旅行(树链剖分+动态开点线段树)
  • 原文地址:https://www.cnblogs.com/twodog/p/12134860.html
Copyright © 2011-2022 走看看