資料消極式載入,消極式載入

來源:互聯網
上載者:User

資料消極式載入,消極式載入

我們在上網的時候經常會看到這樣的效果,在我們發送請求之後,資料顯示在瀏覽器之前,會有一個圓圈在不斷地轉

今天比較好奇,就找了找資料研究了一下

lazyLoad.jsp

<%@ page language="java" pageEncoding="utf-8"%><%@ taglib uri="/struts-tags" prefix="s"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><script type="text/javascript">                        function check(frm){                                var m = document.getElementById("mFrame");                m.contentWindow.document.getElementById("div_loading").style.display = 'block';                m.contentWindow.document.getElementById("div_main").style.display = 'none';                                return true;            }        </script></head><body>        <div align="center">        <s:form action="searchFile" method="post" target="mFrame"            theme="simple" onsubmit="return check(this)">            <table class="tab_frm" width="100%">                <tr>                    <td colspan="5" align="center"><s:submit value="查詢"                            cssClass="btn_normal" theme="simple" /> <s:reset value="重設"                            theme="simple" cssClass="btn_normal" /></td>                </tr>            </table>        </s:form>    </div>        <iframe id="mFrame" name="mFrame" src="common/blank.html" frameborder="0" scrolling="auto" width="100%" height="100%" >              </iframe>    </body></html>
mFrame的資料來源來自blank.html

其代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">    </head>    <body>        <div align="center" id="div_loading"            style=" display: none;">            <img src="../images/loading32.gif" />            <br />            <br />            <span style="font-size:15px;font-weight:normal;">資料讀取中,請稍後...</span>        </div>        <div align="center" id="div_main" style="display: block;">            <img src="../images/asdf.png" />        </div>    </body></html>
loading32.gif如下

至於asdf.png是我隨便找的一張圖,lazyLoad.jsp的效果如下:


至於提交的請求searchFile,是一個struts的action

struts.xml如下

         <action name="searchFile" class="cdm.module.file.action.SearchFileAction" method="lazyLoad"><result>/return.jsp</result></action>
對應的出來函數:
    public String  lazyLoad(){        try {            Thread.sleep(5000);        } catch (InterruptedException e) {            // TODO Auto-generated catch block            e.printStackTrace();        }        return SUCCESS;    }
返回的return.jsp就是一個最簡單的顯示

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body>你看見我了嗎?</body></html>

最後的效果

點擊查詢5秒之內

5秒之後,就會顯示return.jsp的內容




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.