Haridesh Yadav Haridesh Yadav - 1 year ago 57
AngularJS Question

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

I am calling a java restful service in angularjs

.success(function(data) {
// console.log(data);
.error(function(data) {

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.


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 Source

You can use Angular $window:

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

Inject $window object in your controller function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download