jQuery / Ajax - 成功消息后重定向到另一个页面

时间:2015-03-27 14:19:44

标签: javascript jquery html ajax

我想在填写联系表单后重定向用户,并显示成功消息。

这是HTML代码:

<div id="wpm_download_1" style="display: inline;">
   The link to the file(s) has been emailed to you.
</div>

这是我尝试的JavaScript:

function() { 
      var isDownloaded = jQuery('#wpm_download_1').text(); 
        if (typeof obj.isDownloaded != 'undefined'){
            window.location = 'http://google.com';
        }

    }

基本上,我希望在通过AJAX发送表单数据后出现此消息时重定向用户:

文件的链接已通过电子邮件发送给您..

3 个答案:

答案 0 :(得分:0)

为什么使用obj.isDownloaded? 这有效:

 jQuery('#wpm_download_1').text(); 
 if (typeof isDownloaded != 'undefined'){
   window.location = 'http://google.com';
 }

您可以随时根据需要调用该功能

答案 1 :(得分:0)

之前,你必须打电话给你的功能。对于重定向,请使用以下哪种方法:

window.location.href示例:

window.location.href = 'http://www.google.com'; //Will take you to Google.

window.open()示例:

window.open('http://www.google.com'); //This will open Google in a new window.

答案 2 :(得分:0)

好吧,经过努力,我刚刚提出这个问题并且有效:

jQuery( document ).ajaxSuccess(function( event, xhr, settings ) {
  window.location.href = 'http://google.com';
});

因为我希望在successful AJAX request完成后重定向。

相关问题