【问题标题】:Show loader animation for 2-3 seconds and then process - .ajaxStart and .ajaxStop显示加载器动画 2-3 秒,然后处理 - .ajaxStart 和 .ajaxStop
【发布时间】:2012-03-09 16:24:01
【问题描述】:

如何显示加载器动画 3 秒然后处理 process.php? 我已经在 ajaxStart 块和 ajaxStop 块中使用 setTimeout() 方法进行了尝试,但这不起作用。

<script type="text/javascript">
$(document).ready(function(){

$('#loading')
.hide()  // hide it initially
.ajaxStart(function() {
    $(this).show();
})
.ajaxStop(function() {
    $(this).hide();
});

    $("#myform").validate({
        debug: false,
        rules: {
            name: "required",
            email: {
                required: true,
                email: true
            }
        },
        messages: {
            name: "Please let us know who you are.",
            email: "A valid email will help us get in touch with you.",
        },
        submitHandler: function(form) {
            // do other stuff for a valid form
            $.post('process.php', $("#myform").serialize(), function(data) {

            $('#results').html(data);
            });
        }
    });
});
</script>

这是表格:

<form name="myform" id="myform" action="" method="POST">  
<!-- The Name form field -->
    <label for="name" id="name_label">Name</label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>
<!-- The Email form field -->
    <label for="email" id="email_label">Email</label>  
    <input type="text" name="email" id="email" size="30" value=""/> 
    <br>
<!-- The Submit button -->
    <input type="submit" name="submit" value="Submit"> 
</form>
<!-- We will output the results from process.php here -->
<div id="results"><div>

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

【问题讨论】:

    标签: php ajax forms


    【解决方案1】:

    这是我的一个脚本的摘要。

    $(document).ready(function() {
        $.ajaxSetup ({  
            cache: false  
        });  
        $("#header-ajaxload").ajaxStart(function() {
            $(this).html(ajax_load);
        });
    $("#header-ajaxload").ajaxStop(function() {
            $(this).html('');
        });
        $("#header-ajaxload").ajaxError(function() {
            $(this).text( "Triggered ajaxError handler." );
        });
    });
    
    var ajax_load = "<img src='home/img/ajax_load.gif' alt='loading...' />";
    

    【讨论】:

      猜你喜欢
      • 2012-08-23
      • 1970-01-01
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      相关资源
      最近更新 更多