M
M
Maxim Dunayevsky2015-05-08 14:21:29
JavaScript
Maxim Dunayevsky, 2015-05-08 14:21:29

Is it possible and how to extend the XMLHttpRequest constructor?

Hello!
Found that the AngularUI team has implemented a file upload plugin - ui.upload . The plugin is definitely good, but in the body it uses the usual XMLHttpRequest instead of $http. It's not too bad, but there are problems with the Django REST Framework, because in this case, setting the CSTFToken at the application start stage has no effect:

Application.run(['$http', '$cookies', function($http, $cookies) {
    var token = $cookies.csrftoken;
    $http.defaults.headers.common['X-CSRFToken'] = token;
    $http.defaults.headers.post['X-CSRFToken'] = token;
}]);

Django REST Framework expects the X-SCRFToken parameter in the header , doesn't find it and throws an error. I created an Issue on GitHub , but the release date is unknown.
This module does not have a provider either, and changing the options property has no effect.
As a result, I had an idea - "Why not override the standard XMLHttpRequest constructor so that the necessary headers are already set there?"
I know extending built-in classes is a VERY bad idea.
I know it's better to wait for the plugin to be updated.
The question is purely theoretical, it is unlikely that I will use the solution in real work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-05-08
@dunmaksim

The most normal apploader on angular.
https://github.com/danialfarid/ng-file-upload

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question