Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jQuery to redirect? [closed]

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.

like image 828
Robert Avatar asked Jan 29 '13 20:01

Robert


People also ask

How do I redirect to another page?

How to Redirect to Another Page in HTML. To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.

How do I link one JavaScript page to another?

Answer: Use the JavaScript window. location Propertylocation property to make a page redirect, you don't need any jQuery for this. If you want to redirect the user from one page to another automatically, you can use the syntax window. location. replace("page_url") .


1 Answers

You forgot the HTTP part:

window.location.href = "http://example.com/Registration/Success/";
like image 173
Joseph Silber Avatar answered Oct 02 '22 00:10

Joseph Silber