1
if(jQuery("#form_fill_hours").validationEngine('validate')){

    alertify.confirm("Are you sure you want to submit this exam form to your teacher?", function (e) {
    if (e) {
        alertify.set({ delay: 10000 });
        alertify.success("Your exam form has been submitted");
        $.blockUI.defaults.message = "<h1 class='block_msg'>Please Wait...</h1>";
        $.post( SITE_URL+"fill/save/saveformexam?type=1",$("#form_fill_hours").serialize(), function( data ) {
            window.location.href="<?php echo EXAM_URL."exam/weekly/index?week=".$_GET['week'] ?>";
        });
    } else {
        alertify.error("Your exam form is not submitted");
    }
});
            return false;
    }else{
            return false;
    }

使用 alertify,我10为成功消息设置了秒延迟,但它不起作用?我只需要向用户显示成功警报,然后重定向到同一页面。

尝试使用delay但不工作:

alertify.success("Your exam form has been submitted");//show alert to user
delay(100);//wait for 10 secs and then post form data
$.post( SITE_URL+"fill/save/saveformexam?type=1",$("#form_fill_hours").serialize(), function( data ) {
                window.location.href="<?php echo EXAM_URL."exam/weekly/index?week=".$_GET['week'] ?>";
            });

我如何在成功消息中设置一些延迟,以便用户可以看到它,然后才将表单详细信息发布到控制器操作?

4

1 回答 1

1

.delay()仅用于 jQuery 效果之间。这是文档所说的

.delay() 方法最适合在排队的 jQuery 效果之间进行延迟。因为它是有限的——例如,它不提供取消延迟的方法——.delay() 不能替代 JavaScript 的原生 setTimeout 函数,这可能更适合某些用例。

因此,在 post 方法之前创建延迟的唯一方法是 settimeout

setTimeout(function(){
  $.post( SITE_URL+"fill/save/saveformexam?type=1",$("#form_fill_hours").serialize(), function( data ) {
    window.location.href="<?php echo EXAM_URL."exam/weekly/index?week=".$_GET['week'] ?>";
  });
}, 1000);
于 2015-07-09T11:22:12.957 回答