zoukankan      html  css  js  c++  java
  • bulletproof ajax:ajax 载入时显示动画

    The simplest format for this kind of image is an animated GIF
    file. The exact image can be anything you like, as long as it features
    a smoothly looping animation. Rotating shapes, spinning
    arrows, and barbershop-pole progress bars are all popular conventions
    for indicating activity.
    Here’s a short function called displayLoading. It takes a single argument,
    which is an element in the document. This element is first emptied by removing
    all of its child nodes. Then, a newly created img element is appended.

    function displayLoading(element) {
    while (element.hasChildNodes()) {
    element.removeChild(element.lastChild);
    }
    var image = document.createElement("img");
    image.setAttribute("src","loading.gif");
    image.setAttribute("alt","Loading...");
    element.appendChild(image);
    }

    Now I can update the contact details example to use this function. I want to
    execute it at the same time that I’m starting the Ajax request in the grabFile
    function:

    function grabFile(file) {
    var request = getHTTPObject();
    if (request) {
    displayLoading(document.getElementById("details"));
    request.onreadystatechange = function() {
    parseResponse(request);
    };
    request.open("GET", file, true);
    request.send(null);
    return true;
    } else {
    return false;
    }
    }

    When a name is clicked, a GIF animation appears in the “details” div,which is where that person’s details will appear.

    Once the Ajax call is successfully completed, the loading image is obliterated
    by the use of innerHTML in the parseResponse function:

    function parseResponse(request) {
    if (request.readyState == 4) {
    if (request.status == 200 || request.status == 304) {
    var details = document.getElementById("details");
    details.innerHTML = request.responseText;
    }
    }
    }
  • 相关阅读:
    12.27 cf div3 解题报告
    网络流24题 P2754 [CTSC1999]家园
    P3690 【模板】Link Cut Tree (动态树)
    P2147 [SDOI2008]洞穴勘测
    P3203 [HNOI2010]弹飞绵羊
    P4172 [WC2006]水管局长
    P3979 遥远的国度
    P3128 [USACO15DEC]最大流Max Flow
    P3178 [HAOI2015]树上操作
    [SDOI2014]旅行
  • 原文地址:https://www.cnblogs.com/youxin/p/2666630.html
Copyright © 2011-2022 走看看