2

I'm working with a JavaScript framework (wakanda) in back-end that uses XHR requests, and with AngularJS in front-end.

I used angular-loading-bar that works perfectly and automatically with HTTP requests, but it doesn't work automatically with XHR requests.

is there any way to make it work AUTOMATICALLY XHR?

dev17js
  • 131
  • 6

1 Answers1

0

XHR vs HTTP

First XHR stands for the "XmlHTTPRequest API" (). (see also the W3C spec version & the Mozilla documentation) This API, introduced by Microsoft, then standardised by WHATWG & W3C,facilitated the creation of Ajax based Websites and Web Applications. When you make an XHR request, it sends an HTTP request

$http vs HTTP

angular-loading-bar use an angularJS $http interceptor to listen all HTTP requests done using the angular $http API. The angular $http API is using XHR to make its HTTP requests, but it does not overwrite XMLHttpRequest nor it does for its prototype. So it can not intercept HTTP requests made from code using directly XHR.

angular-wakanda HTTP requests

angula-wakanda is an angular service written on top of the Wakanda Framework data provider. It can then more easily update itself with new features that are occasionally added to the Wakanda HTTP (REST, JSON-RPC) APIs and/or to the Wakanda data provider one. As this data provider is framework agnostic (can be used with dojo, backbone, or anything else), it does not use the angular specific $http API and its HTTP requests are then not intercepted by the angular-loading-bar

How to fix it?

Introducing low-level adapters layer for the Wakanda data-provider is something that have been discussed by the Wakanda team. It might then allow to choose which HTTP API to use in some dedicated contexts (as in nodejs where XHR is not the native HTTP API). There should be a "data provider" dedicated github repository added to the Github Wakanda Team Account in the future. In the meantime, you can send a feature request to the Angular-Wakanda Github repository (do not hesitate to mention this Stack overflow answer), and why not, also try to do a fork for a proposal ;-)

Alexandre Morgaut
  • 1,246
  • 13
  • 14