shamsee
shamsee

Reputation: 1399

How to redirect on particular url in ajax

I am validating a login form using ajax call. It is working great when you enter the wrong information. But if you enter the right credentials nothing happens. I am confused what to do? sample code:

$.ajax({
                type: 'POST',
                url: URL +'/foo/',
                data: {'uname': name, 'password':pass},
                success: function(data) {
                    if (data["success"] === "false") {
                        //show some message
                        $("#password").val("");
                    }
                                    else {
                                     // here i want to redirect to some url say, /bar/
                                      I am confused how to do it.
                },
                dataType: "json",
            });
            return false

Upvotes: 1

Views: 2827

Answers (3)

Deepak
Deepak

Reputation: 922

Try this:

window.location = url;

Upvotes: 0

RicardO
RicardO

Reputation: 1229

$(location).attr("href","url here")

Upvotes: 0

kobe
kobe

Reputation: 15835

you can use javascript.

location.href="new url";

it will take you to the new url

var querystringParam="sample";

var tempUrl="http://www.test.com?" + "variablettopass=" + querystringParam

location.href=tempUrl;

if you have more than one append to query string...

if you want your server name from browser window use this code

window.location.hostname

but if you do location.href // it will take care...i just gave you for info

Upvotes: 3

Related Questions