node.js - Redirect to external URL -


i using angularjs nodejs.

i have scenario when upon successful http post request, need redirect user.

in client through angularjs, make http post request route:

$http.post('/apath', data)     .success(function (result) {         //handle success     })     .error(function (err) {         //handle error     }); 

this route handled within nodejs actual post. upon success, within route handler, redirect:

function handlepostrequest (req, res) {     //route handler     //http post request      //following code called when post request successful     if (result) {         //successful post         res.redirect("http://www.google.com");     } } 

however, browser not navigate google. instead, in error handler of post request within angularjs client, control reached.

i checked server , find post request returned status code 302 , picked error handler post request in client.

i cannot figure out why, when server executes redirect code, control still reaches client , error handler. how redirect successfully?

is http post in angular or xhr? if it's xhr can't redirect client serverside, you'd need send error handle in clientside script such as:

$http({    method: 'post',    url:    'yoururl', }).success(function(data, status, headers, config) {     // success stuff }).error(function(data, status, headers, config) {     if (status == 302) {        window.location = headers('location');     } }) 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -