Haridesh Yadav Haridesh Yadav - 17 days ago 5
AngularJS Question

How to go to the url return by a restful service as response

I am calling a java restful service in angularjs

$http
.post($scope.url,datatest)
.success(function(data) {
console.log('success');
// console.log(data);
$scope.responseURL=data;
console.log($scope.responseURL);
})
.error(function(data) {
console.log('error');
});


Here the data is containing a url and I want to go to that url after success of service call.

Actually this is a transaction page where use will hit place Order button and then a service will be called which will return the url of payment getway.
Now I am supposed to redirect to that payment getway url.

Thanks

Edit:
Both the answer bellow are correct but the problem was, I was getting url as 'www.xyz.com/abc....' that's why it was being appended in the current url.

So I just prefixed the response url wiht 'http://' and it worked both way, the same tab and new tab as well.

Answer

You can use Angular $window:

$window.location.href = $scope.responseURL;

Inject $window object in your controller function.