A
A
Andrey Shiryaev2014-11-12 23:41:31
JavaScript
Andrey Shiryaev, 2014-11-12 23:41:31

How to set global http header handler from server in angular?

In yii there is such a thing for handling redirects on the side of browsers during ajax requests.

$(document).ajaxComplete(function (event, xhr, settings) {
      var url = xhr.getResponseHeader('X-Redirect');
      if (url) {
         window.location = url;
     }
  });

How to hang the header handler globally in angular as well?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-11-13
Protko @Fesor

firstly, not in Yii but in jQuery.
Secondly, we read the documentation for the $http service and, in particular, the interceptor section .
Third, use everything global carefully and only if you know what you're doing. Otherwise, it's better to make your own wrapper over $http and resolve everything there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question