简体   繁体   English

显示带有非ajax页面的加载对话框

[英]Display a loading dialog with non-ajax pages

I've the current situation: 我目前的情况:

  1. Have a Link in some HTML page. 在某些HTML页面中有一个链接。

  2. When the user click that Link, an NORMAL (vs Ajax) HTTP request is being sent to a Web Server (typically a Java Servlet) 用户单击该链接时,正向Web服务器(通常是Java Servlet)发送一个NORMAL (与Ajax)HTTP请求。

  3. After that, of course the browser will bring the contents from the server and start rendering it. 之后,浏览器当然会带走服务器中的内容并开始渲染。 (actually it's the same page with modified contents - don't ask me to do it in ajax, cause it is the requirements) (实际上,这是同一页,其内容已修改-不要要求我使用Ajax进行操作,因为这是要求)

Before step 3 is being done (while the page is being loaded) I need to display some frame to the user saying something like loading .... 在完成第3步之前(在加载页面的同时),我需要向用户显示一些框架,例如loading ....

Well, just populate a div somewhere on the page with "Loading..." when the link is clicked. 好吧,单击链接时,只需在页面上的某个位置用“正在加载...”填充div。 Here's some rough code 这是一些粗糙的代码

$('#yourlink').click(function(){
   $('#loading').html('Loading....'); 
}); 


<div id="loading">
</div> 

And when the page loads, the current loading div will be replaced with an empty one, this will signify that the loading is complete. 当页面加载时,当前的加载div将替换为一个空的div,这表示加载已完成。

Another approach: 另一种方法:

The css 的CSS

#loading
{
  display: none; 
}

The html HTML

<div id="loading">
    Loading....
</div>

The js 的js

$('#yourlink').click(function(){
    $('#loading').show(); 
});  

Well, there's several non Ajax ways to do this. 嗯,有几种非Ajax方法可以做到这一点。 The simplest I guess would be to have a giv animated image with your loading bar, which you keep in a hidden div in your initial page: 我猜最简单的是在加载栏上添加一个giv动画图像,并将其保留在初始页面的隐藏div中:

<div style="display:hidden;"><img src="/img/loading.gif"></div>

Then add some javascript to the link/button that submits the page, such as when it is clicked it unhides the div with image. 然后将一些javascript添加到提交页面的链接/按钮中,例如单击该页面时,它将取消隐藏带有图像的div。

There are many ways to do this. 有很多方法可以做到这一点。 I handle it something like this: 我这样处理:

// Any anchor with showOverlay class will invoke the overlay function
$("a.showOverlay").click(function() {
    overlay();
});

// Normal form submits are intercepted. Overlay call also be skipped by
// making the form of class "noOverlay"
$("form").submit(function() {
    var skipOverlay = $(this).hasClass("noOverlay");
    if(!skipOverlay){
        overlay();
    }       
    return valid;
});

// This overlay function uses the blockUI plugin, other methods can also be used
function overlay(){
    $.blockUI({
        fadeIn: 500,
        css: {
            height: '150px',
            top: '35%'
        },
        message: '<div style="margin-top: 40px;"><table align="center" ><tr ><td style="padding-right: 25px;"><img src="/images/wait.gif" /></td><td style="line-height: 25px;"><h1> Just a moment...</h1></td></tr></table></div>'
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM