Q:

how to redirect in the callback of a jquery post

my home page upon receiving the data does not redirect to login page. 
here is the home page js:
$(function(){
    const submit = $('#submit');
    const save = $('#save');
    const email = $('#email');
    const username = $('#username');
    const password = $('#password');
    const userlogin = $('#Username login');
    const passlogin = $('#Password login');
    save.click(function(e){
        e.preventDefault();
        $.post('/signup',{
            email:email.val(),
            username:username.val(),
            password:password.val()
        }, function(data){
            console.log(1)
            if(data.username){
            localStorage.setItem("username",data.username)
            }
            window.location.href(data.url)
        })
    })
    submit.click(function(e){
        e.preventDefault();
        $.post('/login',{
            username:userlogin.val(),
            password:passlogin.val()
        }, function(data){
            window.location.href(data.url)
        })
    })
})

this is the routes.js file present on backend
app.post('/signup', function(req,res){
    var a = [req.body.email,req.body.username,req.body.password];
    Users.findOne({
       where: { email: a[0],
        username: a[1],
        password: a[2],
       }

    }).then(users => {
        if (users) {
        res.send({
            url:'/'
        })
        }
        else{
            Users.create({
                email: a[0],
                username: a[1],
                password: a[2],

          }).then(users => {
                res.send({
                    url:'/profile',
                    username: a[1]
                })
          })    
        }
    })
})

I need to redirect to /profile upon receiving a successful callback from the server. But right now the page doesnt load, however the username field is successfully stored in localstorage. 
I believe it is occuring due to window.location.href

A:

You can do it in multiple ways.  
First let me tell you what is wrong in your code,
You have to use, 
window.location.href = "https://www.example.com";

As the notation you wrote is wrong
window.location.href(data.url) // this is wrong

Window.location docs at MDN 
Now coming to alternative way,
You can specify the post method in your markup as well in the action attribute. 
<form name="some_name" method="POST" action="/signup">
... Your Form ...
</form>

