Execute a service after a call ajax in AngularJS, with $window location

I need to save data in a service factory after a ajax call. It all
works without location.href. But it doesn’t work when I put the line
code $window.location.href.
This is the code:

scope.res = function(id){
.then (function(response){commonVarService.setA(response.A);
.catch(function(err) {console.log(err)});

Where, factoryService allow to make an ajax call, wherease
commonVarService allow to memorize data in variables of service.
If there isn’t the $window.location.href="" it all works, but when there
is the $window.location.href, the application redirect in the new page
without memorize the variable.
where is it my Error? Is there some good solution?
Thanks in advance.