Alertify - 显示延迟成功消息

时间:2015-07-09 10:48:48

标签: jquery alertify

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'] ?>";
            });

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

1 个答案:

答案 0 :(得分: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);