English 中文(简体)
显示页面之间正在装入信件的页面
原标题:Display a Page Loading message between pages

我的网站上有一个 fafor 网站,提交时用户从 Page1.html Page2.html

我想在所提交的表格和“加载2号页面”的表格之间显示一个信息

有人能给我举个例子吗?

最佳回答

如果您的表格通过 ajax 提交数据, 您可以尝试一下:

$( form#myform ).submit(function(e) {
   e.preventDefault();
   $( #message ).html( Sending.... );  // #message may be a div that contains msg
   $ajax({
     url:  url_to_script ,
     data:  your_data ,
     success: function(res) {
       // when submit data successfully then page reload
       window.location =  page2.html 
     }
   });
});
问题回答

您所要做的事情无法通过标准表格提交方式完成 。

您会想要使用 ajax 提交表格, 并在等待回复时显示“ 请稍候 ” 消息 。 一旦收到回复, 并验证回复是否有效, 然后您就可以将用户转到您现在拨打的第2页的页面上 。

通过 ajax 提交表格的最简单方式是 < a href=" https://stackoverflow.com/ questions/672045/how-to-sergize- a-form-in-to- a-of-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-to-tree-tree-st-结构”> 将表格序列化

然后,联署材料将需要解释下一步行动。

This is not tested, but copied and pasted from various working projects. You ll need to download and include the json2.js project.

<强>第1页

<div id= pleaseWait >Please Wait...</div>
<form id="theForm" onsubmit="doAjaxSubmit();">
    <input type= text  name= age  id= age  />
    <input type= submit  value= submit >
</form>

<script type="text/javascript">
    function doAjaxSubmit(){
        var j = JSON.stringify($( #theForm ).serializeObject());

        $( #pleaseWait ).slideDown( fast );
        $.post( processor.php?j=  + encodeURIComponent(j), function(obj){
            if(obj.status== OK ){
                window.location= page2.php ;
            }else{
                $( #pleaseWait ).slideUp( fast );
                alert( Error:   + obj.msg);
            }
        },  json );
        return(false);
    }    


    $.fn.serializeObject = function(){
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value ||   );
            } else {
                o[this.name] = this.value ||   ;
            }
        });
        return o;
    };
</script>

<强度 > 处理器.php

<?php

    $j=json_decode($_POST[ j ], true);


    if ((int)$j[ age ]<=0 || (int)$j[ age ]>120){
       $result = array( status => ERR ,  msg => Please Enter Age );
    }else{
        //Do stuff with the data. Calculate, write to database, etc.
        $result = array( status => OK );
    }
    die(json_encode($result));
?>

这基本上与下面的答案非常相似(通过),但我的示例展示了如何在无需手动构建数据对象的情况下通过整个数据对象,展示了如何在 PHP 侧验证,以及返回适当的 JSON 数据以改变用户方向,或显示错误,并使用动画显示消息。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签