最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQueryAjax - Redirect to another page after succes message - Stack Overflow

programmeradmin6浏览0评论

I want to redirect the user after filling up the contact form and the success message appears.

Here's the HTML code:

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

and here's the JavaScript I'm trying:

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

    }

Basically, I want to redirect the user when this message appears after sending form data through AJAX:

The link to the file(s) has been emailed to you..

I want to redirect the user after filling up the contact form and the success message appears.

Here's the HTML code:

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

and here's the JavaScript I'm trying:

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

    }

Basically, I want to redirect the user when this message appears after sending form data through AJAX:

The link to the file(s) has been emailed to you..

Share Improve this question edited Mar 27, 2015 at 14:48 Faizan Ali asked Mar 27, 2015 at 14:19 Faizan AliFaizan Ali 1,0133 gold badges18 silver badges32 bronze badges 3
  • Not a plete picture there. Are you having problems with that? – bloodyKnuckles Commented Mar 27, 2015 at 14:23
  • 1 You need to initiate your function. Right now it just exists. You should give your function a name and then call it somewhere function myFunction(){}; and then call it later myFunction(); – KJ Price Commented Mar 27, 2015 at 14:24
  • isDownloaded is necessarily a string (you ask for .text() ). obj.isDownloaded is undefined. – Jeremy Thille Commented Mar 27, 2015 at 14:27
Add a ment  | 

3 Answers 3

Reset to default 1

Alright, after trying hard I just came up this and it worked:

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

Becuase, I wanted to be redirected after the successful AJAX request is plete.

Why do you use obj.isDownloaded ? Here it works :

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

Is up to you to call the function whenever you need it

Before, you must call your function. And for redirect please which one method below:

window.location.href example:

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

window.open() example:

window.open('http://www.google.'); //This will open Google in a new window.
发布评论

评论列表(0)

  1. 暂无评论