Angular interceptor intercepts ajax requests

the company project uses angularJS, and also uses some jquery plug-ins in the project, such as bootstrap table, which comes with ajax requests. Now the front end needs to act as an interceptor to handle http requests uniformly. Excuse me, how can we intercept these jquery requests in the angular interceptor?

Mar.10,2021

monkey patch the prototype method of the XMLHttpRequest object, because no matter how much the request library is encapsulated, it is usually XMLHttpRequest , and some may also use fetch of modern browsers, such as

.
(function(send) {

    XMLHttpRequest.prototype.send = function(data) {

        // do something...

        send.call(this, data);
    };

})(XMLHttpRequest.prototype.send);

if you want to do this, pay attention to performance issues.


there is another way to reset the prototype.
is processed by angular and jQuery , and then the processing method is reused.

angular the method to configure the interceptor is $httpProvider.interceptors
jQuery the method to configure the interceptor is jQuery.ajaxSetup

you can configure these two items with the same interceptor method to modify an interceptor. All requests will take effect.

also saw that the subject got bootstrap table , recommended a table component GridManager

.

go to Open Source China to see if there are similar articles!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb4fbe-482ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb4fbe-482ef.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?