【问题标题】:jQuery/Ajax - Redirect to another page after succes messagejQuery/Ajax - 成功消息后重定向到另一个页面
【发布时间】:2015-03-27 14:19:43
【问题描述】:

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

这是 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发送表单数据后出现此消息时重定向用户:

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

【问题讨论】:

  • 那里没有完整的图片。你有这个问题吗?
  • 你需要启动你的函数。现在它只是存在。你应该给你的函数一个名字,然后在某个地方调用它function myFunction(){};,然后再调用它myFunction();
  • isDownloaded 必须是一个字符串(您要求 .text() )。 obj.isDownloaded 未定义。

标签: javascript jquery html ajax


【解决方案1】:

好的,经过努力,我想出了这个,它成功了:

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

因为,我想在 successful AJAX request 完成后被重定向。

【讨论】:

    【解决方案2】:

    你为什么使用 obj.isDownloaded ? 它在这里工作:

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

    由您在需要时调用该函数

    【讨论】:

      【解决方案3】:

      在此之前,您必须调用您的函数。对于重定向,请使用以下哪种方法:

      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.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-07
        • 1970-01-01
        • 2011-02-26
        • 1970-01-01
        • 2019-01-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多