Express js - can't redirect
Browser does not redirect the window on redirect on ajax response. Redirect the browser with javascript.
In server send the new site as content, for example.
res.contentType('application/json');var data = JSON.stringify('http://site.example.com/')res.header('Content-Length', data.length);res.end(data);
In client
var req = jQuery.post( "http://www.mysite.com:3000"+"/dologin", {"username" : username, "password" : password}, 'json').error(function(){ alert("an error occurred"); }).success(function(data) { window.location = data; });
I'm doing something like this when using OAuth2. I have an link to one of my pages and this in turn redirects to google.
To redirect to another location the following code does the actual redirect
app.get('/GoogleRequestAuthorization.html',function(req,res) {....res.writeHead(302, {location: url});res.end();
});
url being the address you want to redirect to.
The full function is...