0

simply put I can't get any redirection to work after my 'insert_callback', here is my code

$('#email').focusout(function() {
var email = $('#email').val();
$.post('process_info.php', { email: email }, function(callback) { 
    $('#email_feedback').html(callback);
    if(callback == 'awesome') {
        $('#submit').removeClass('hidden');
        $('#quiz_sub').submit(function() {
            $.post('submit_info.php', { email: email }, function(insert_callback) { 
                //want redirection to happen here
            });
        });
    }
});
});

any help is greatly appreciated. Thanks!

skevthedev
  • 447
  • 1
  • 7
  • 20
  • possible duplicate of [change url and redirect in jquery](http://stackoverflow.com/questions/846954/change-url-and-redirect-in-jquery) – Maxime Pacary Nov 16 '11 at 19:47

4 Answers4

1
 //want redirection to happen here
 window.location.href = "http://www.google.com/"

or How to redirect to another webpage in JavaScript/jQuery?

Edit: it look like your callback is not executed... alert it or log to console like Rosario suggests, is not working, continue debug:

alert(callback);
if(callback == 'awesome') {
    $('#submit').removeClass('hidden');
    $('#quiz_sub').submit(function() {
        alesrt('submiting...');
        $.post('submit_info.php', { email: email }, function(insert_callback) { 
            //want redirection to happen here
            alert('before redirect...');
            window.location = "http://stackoverflow.com";
        });
    });
}
Community
  • 1
  • 1
bensiu
  • 24,660
  • 56
  • 77
  • 117
  • yeah i have tried both of those but for some reason they are not working, i have tried both the relative link and direct link – skevthedev Nov 16 '11 at 19:53
  • is your callback function is executed ? alert it or log to console like Rosario suggests. – bensiu Nov 16 '11 at 20:08
  • the alert is not working, it is initially just resetting the page – skevthedev Nov 16 '11 at 20:11
  • fixxed it? i changed submit() method to click() and it works fine now! Im not sure if it is proper convention, but I cant think of anything else – skevthedev Nov 16 '11 at 20:30
0

You can try:

$(location).attr('href', redirect_page);
Mathieu Mahé
  • 2,647
  • 3
  • 35
  • 50
0
window.location.href = 'http://google.com';
maxedison
  • 17,243
  • 14
  • 67
  • 114
0

First check if you are getting to the final process.

    $('#quiz_sub').submit(function() {
        $.post('submit_info.php', { email: email }, function(insert_callback) { 
            //want redirection to happen here
            alert("your there!");
            window.location = "http://stackoverflow.com";
        });
    });

Then add the redirect. Use window.location ="http://stackoverflow.com";

Leysam Rosario
  • 379
  • 2
  • 11