Robert Robert - 6 months ago 10
jQuery Question

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.

Answer

You forgot the HTTP part:

window.location.href = "http://example.com/Registration/Success/";
Comments