在jQuery帖子中重定向之前显示通知

时间:2012-05-29 17:10:31

标签: jquery ajax

我正在尝试在将用户重定向到另一个页面之前显示成功通知。我正在使用带有jQuery 1.7的Apprise插件。问题是它重定向而不显示通知。如果我取出重定向,通知工作完美。谢谢你的帮助。

$.ajax({
            type:"POST",
            url:"create/process_vote.php",
            data: { answerid: aid },
                success: function(){
                    $(".status").text('Thank you for voting!');
                    $(".status").fadeIn("slow");
                    $(".status").delay(2000).fadeOut(1000);
                    window.location.href = "results.php?id=" + aid;
                }
    });

3 个答案:

答案 0 :(得分:0)

使用 window.confirm()

success: function(){
                    $(".status").text('Thank you for voting!');
                    $(".status").fadeIn("slow");
                    $(".status").delay(2000).fadeOut(1000, function() {
                      // if user agreed
                      // window.confirm() in short just confirm()
                      if(window.confirm('Are you sure?')) { 
                          window.location.href = "results.php?id=" + aid;
                      }

                    });

                }

答案 1 :(得分:0)

Apprise文档显示它有一个回调函数。将重定向代码放在回调中。

$(document).ready(function(){
    apprise('Redirect?', {'verify' : true}, function(r){
        if (r) {
            window.location = 'http://google.com'
        }
    })
});

Apprise Docs

答案 2 :(得分:0)

success: function(){
  $(".status").text('Thank you for voting!');
  $(".status").fadeIn("slow");
  $(".status").delay(2000).fadeOut(1000);

  setTimeout(function(){ window.location.href = "results.php?id=" + aid; }, 2000);

}
相关问题