使用 Jquery 显示模式“请稍候”对话框消息

发布于 2024-09-29 03:13:34 字数 1789 浏览 4 评论 0原文

是否可以在用户单击链接时阻止页面,并仅在服务器返回响应后才启用该页面。 我最近遇到一个问题,多次单击页面上的链接导致同时发生两个更改。

问题是该页面允许多次提交。我已经使用 Struts saveToken() 和 isValidToken() 在服务器端解决了这个问题,以防止这种情况再次发生。这将确保如果收到多个提交,则不会处理第二个提交。

现在我遇到的问题是,如果用户单击提交链接两次,则第一个请求有效,但第二个请求无效。用户被重定向到错误页面,没有意识到第一个请求确实已通过。

我认为解决方案是在单击链接时阻止/禁用该链接。我知道您可以使用 javascript 来禁用该链接,但我想使用我在多个站点上看到的 AJAXy 模式对话框之一。基本上,当您单击链接时,会出现一个弹出对话框,其中包含一条消息“请稍候..”。背景会淡出,用户无法执行任何操作,直到服务器返回响应为止。我看到的大多数示例似乎都是基于 Ajax 的。我的页面没有使用 Ajax。

实现这个模式对话框的最简单方法是什么?我一直在四处寻找,有几个可用于 JQuery 的插件,但鉴于我是新手,我不太了解它。有人可以向我展示如何使用 Jquery 执行此操作的示例吗?

谢谢

编辑

以这个为例,

            //CONTROLLING EVENTS IN jQuery
            $(document).ready(function(){

                //LOADING POPUP
                //Click the button event!
                $("#button").click(function(){
                    //centering with css
                    centerPopup();
                    //load popup
                    loadPopup();
                });

                //CLOSING POPUP
                //Click the x event!
                $("#popupContactClose").click(function(){
                    disablePopup();
                });
                //Click out event!
                $("#backgroundPopup").click(function(){
                    disablePopup();
                });
                //Press Escape event!
                $(document).keypress(function(e){
                    if(e.keyCode==27 && popupStatus==1){
                        disablePopup();
                    }
                });

            });

我希望当我点击链接时触发这些事件。该链接本身指向另一个 JavaScript 函数。即

<a href="javascript:submitform();">confirm</a>

我如何调用submitform() javascript 函数内部的jquery 位?最好是在 Submitform() 完成之后。

Is it possible to block a page when a user clicks on a link and only enable it once the response has come back from the server.
I had a problem recently where a link was clicked on a page several times resulting in two simultaneous changes.

The problem was that the page was allowing multiple submit. I have already resolved this on the server side using Struts saveToken() and isValidToken() to prevent this to happen again. This will ensure that if multiple submits are recieved the second one is not processed.

Now the problem i am having is if the user clicks on the submit link twice, the first request is valid but the second is not. The user is redirected to an error page not realising that the first request did go through.

I think the solution is to block/disable the link when it is clicked. I know you can use javascript to disable the link but i would like to use one of the AJAXy modal dialog boxes that i've seen on several sites. Basicly when you click on the link, a pop dialog shows up with a message "Please wait..". The background is faded out and the user cannot do anything until the response has come back from the server. Most of the examples that i see seem to be Ajax based. My page does not use Ajax.

What is the easiest way to achieve this modal dialog box? I have been looking around and there are several plugins available for JQuery but given that i am new to it i dont quite understand it. Can someone show me an example of how to do this using Jquery?

Thanks

EDIT

Take this for example,

            //CONTROLLING EVENTS IN jQuery
            $(document).ready(function(){

                //LOADING POPUP
                //Click the button event!
                $("#button").click(function(){
                    //centering with css
                    centerPopup();
                    //load popup
                    loadPopup();
                });

                //CLOSING POPUP
                //Click the x event!
                $("#popupContactClose").click(function(){
                    disablePopup();
                });
                //Click out event!
                $("#backgroundPopup").click(function(){
                    disablePopup();
                });
                //Press Escape event!
                $(document).keypress(function(e){
                    if(e.keyCode==27 && popupStatus==1){
                        disablePopup();
                    }
                });

            });

I would like these events to be triggered when i click on a link. The link itself points to another javascript function. i.e.

<a href="javascript:submitform();">confirm</a>

How can i call the jquery bits inside of the submitform() javascript function? Preferabley after the submitform() has completed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌酱 2024-10-06 03:13:34

看一下 jQuery.dialog(网站),它允许您将页内 div 显示为模式或者甚至从另一个页面获取您的内容。

<div id="progress" class="dialogContent" style="text-align: left; display: none;">
<img src="../../global/style/default/images/ajax-loader.gif" style="margin-right: 5px;" />
<asp:literal id="literalPleaseWait" runat="server" text="Please wait..." />
</div>

然后调用下面的函数来显示对话框

 function ShowProgressAnimation() {
    var pleaseWaitDialog = $("#progress").dialog(
    {
    resizable: false,
    height: 'auto',
    width: 150,
    modal: true,
    closeText: '',
    bgiframe: true,
    closeOnEscape: false,
    open: function(type, data) {
    $(this).parent().appendTo($("form:first"));
    $('body').css('overflow', 'auto'); //IE scrollbar fix for long checklist templates
    }
    });
    }

Have a look at jQuery.dialog (website), it allows you to either show in-page divs as modals or alternatively even get your content from another page.

<div id="progress" class="dialogContent" style="text-align: left; display: none;">
<img src="../../global/style/default/images/ajax-loader.gif" style="margin-right: 5px;" />
<asp:literal id="literalPleaseWait" runat="server" text="Please wait..." />
</div>

and then call the function below to show the dialog

 function ShowProgressAnimation() {
    var pleaseWaitDialog = $("#progress").dialog(
    {
    resizable: false,
    height: 'auto',
    width: 150,
    modal: true,
    closeText: '',
    bgiframe: true,
    closeOnEscape: false,
    open: function(type, data) {
    $(this).parent().appendTo($("form:first"));
    $('body').css('overflow', 'auto'); //IE scrollbar fix for long checklist templates
    }
    });
    }
奢华的一滴泪 2024-10-06 03:13:34

您可以使用透明度覆盖绝对定位的 div 图层,以捕获任何鼠标点击,从而防止页面中的任何对象做出反应。

然后在其上放置另一个 div 以显示消息。

有几个 js 库可以做这样的事情,其中​​许多是基于 jQuery 构建的,所以请查看 jquery 模式弹出窗口。

You could overlay a absolutly positioned div layer with transparency that captures any mouseclicks preventing any objects in the page from reacting.

Then an another div ontop of that to display a message.

There are several js libraries to do such things, many which builds on jQuery, so look on jquery modal popup.

树深时见影 2024-10-06 03:13:34

在您执行 form.submit() 之后,在您的 Submitform() 内部直接调用 centerPopup() 和 loadPopup() 以显示弹出窗口

Inside you submitform() after you do the form.submit() call the centerPopup() and the loadPopup() directly to show the popup window

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文