Skip to content Skip to sidebar Skip to footer

Using $http.post And Res.redirect Without Resolving The Promise

I am using an $http.post call to my server and sending over some user data: $http.post('/streamdb/create/',{user:$scope.user.username}) My server then performs a series of operati

Solution 1:

Your server side code cannot redirect the browser from an ajax response. The only reason that redirecting from the server side works without ajax is you are actually sending a fresh page each time, so a redirect means simply serving a different page. Ajax requests dont get served an entire new page as a response, so you are stuck on the current one. You need to go the 'wasteful' route :) Return the id in the response body and redirect using the angular $location service like you mentioned. I recommend using a promise and performing the redirect once it resolves.


Post a Comment for "Using $http.post And Res.redirect Without Resolving The Promise"