javascript - Handle an express redirect from Angular POST -
i'm using expressjs api , i'm using angular hit post. respond redirect express sending. success angular post returns html of page intend redirect nothing happens on dom. can see redirect working in network traffic, , console.log data, below contains dom of redirected page.
how can refresh dom, reflect successful post, or handle "redirect"?
angular code:
$http({method: 'post', url: '/login', data:formdata}). success(function(data, status, headers, config) { console.log(data) }). error(function(data, status, headers, config) { }); $scope.username = '';
expressjs api:
app.post('/login', function(req, res){ var name = req.param('name', null); // second parameter default var password = req.param('password', "changeme") // lots authenticationcode // returns succesfful login res.redirect('http://localhost:3000/'); }); // end app.post
console.log(data) (from angular post success)
returns html of page intended redirect
angularjs meant work client-side framework coupled (mostly) restfull apis. login api isn't supposed return html, supposed return instruction redirect. in case should call $location.url('/')
in $http
success callback, use angular router "redirect" '/' (the root url).
Comments
Post a Comment