Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XMLHttpRequest = function() {
- this.onreadystatechange = function() { };
- this.readyState = 0;
- this.response = null;
- this.responseText = null;
- this.responseType = "blob";
- this.responseURL = null;
- this.responseXML = null;
- this.status = 0;
- this.statusText = "";
- this._loadcallbacks = [];
- this._errorcallbacks = [];
- this.onload = function(e) {
- }
- this.onerror = function(e) {
- }
- this.onprogress = function(e) {
- }
- this.abort = function() {
- this._aborted = true;
- };
- this.addEventListener = function(event, callback) {
- if(event === "load") {
- this._loadcallbacks.push(callback);
- } else if(event == "error") {
- this._errorcallbacks.push(callback);
- }
- };
- this.getAllResponseHeaders = function() {
- return null;
- };
- this.open = function (method, url, async, user, password) {
- this._method = method;
- this._url = url;
- this._user = user;
- this._password = password;
- };
- this.overrideMimeType = function(mime_type) {
- this._overrideMime = mime_type;
- };
- this.send = function() {
- if(!this._url) {
- return;
- }
- let this_ref = this;
- requester.request(this._url).then(function(http) {
- this_ref.readyState = 1;
- this_ref.onreadystatechange();
- this_ref.readyState = 2;
- this_ref.onreadystatechange();
- this_ref.readyState = 3;
- this_ref.onreadystatechange();
- this_ref.response = http.response;
- this_ref.responseText = http.responseText;
- this_ref.responseURL = this_ref._url;
- this_ref.status = http.status;
- this_ref.statusText = http.statusText;
- let is_xml = false;
- if(this_ref._overrideMime) {
- if(this_ref._overrideMime === "application/xml" || this_ref._overrideMime == "text/xml") {
- is_xml = true;
- }
- } else {
- let headers = http.getAllResponseHeaders().toLowerCase();
- if(headers.includes("content-type: application/xml") || headers.includes("content-type: text/xml")) {
- is_xml = true;
- }
- }
- if(is_xml) {
- parser = new DOMParser();
- this_ref.responseXML = parser.parseFromString(this_ref.responseText, "text/xml");
- }
- this_ref.readyState = 4;
- this_ref.onreadystatechange();
- this_ref.onload(http);
- for(callback of this_ref._loadcallbacks) {
- callback.call(this_ref, http);
- }
- }, function(exception) {
- this_ref.onerror(exception);
- for(callback of this_ref._errorcallbacks) {
- callback.call(this_ref, exception);
- }
- });
- };
- };
- XMLHttpRequest.prototype = {
- 'UNSENT': 0,
- 'OPENED': 1,
- 'HEADERS_RECIEVED': 2,
- 'LOADING': 3,
- 'DONE': 4,
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement