[javascript] How do I use jQuery to redirect?

I am using a HTML form to submit to a jQuery validation which then sends information to a PHP processing page through ajax.

Everything works 100% apart from when everything comes back true I can't get the page to redirect to a success page.

The code I have is:

$.post(url,{ username: value_login.val(), firstname: value_firstname.val(), lastname: value_lastname.val(), email: value_email.val(), password: value_password.val()} , function(data) {

    if(data == 'success'){

        window.location.href = "http://example.com/Registration/Success/";
    } else {
       $('#error').text('error');
    }

});

I'm thinking you can't redirect using the window.location.href function.

This question is related to javascript jquery

The answer is


Via Jquery:

$(location).attr('href','http://example.com/Registration/Success/');

This is a shorthand Ajax function, which is equivalent to:

$.ajax({  type: "POST",
           url: url,  
          data: { username: value_login.val(), firstname: value_firstname.val(), 
                  lastname: value_lastname.val(), email: value_email.val(),
                  password: value_password.val()
                },
          dataType: "json"
       success: success// -> call your func here  
      });

Hope This helps


I found out why this happening.

After looking at my settings on my wamp, i did not check http headers, since activated this, it now works.

Thank you everyone for trying to solve this. :)