简体   繁体   中英

jQuery/Ajax - Redirect to another page after succes message

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.com';
        }

    }

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..

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

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

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.com'; //Will take you to Google.

window.open() example:

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM