Created
June 22, 2013 12:16
-
-
Save m1el/5840683 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TrueXMLHttpRequest = XMLHttpRequest; | |
XMLHttpRequest = function(){ | |
this.status = 0; | |
this.readyState = 0; | |
return this; | |
} | |
XMLHttpRequest.prototype.open = function(meth, uri, asyn){ | |
if(!uri){ | |
throw {}; | |
} | |
this.method = meth; | |
this.uri = uri; | |
this.asyn = asyn; | |
}; | |
XMLHttpRequest.prototype.send = function(postdata){ | |
var self = this; | |
self.post = postdata; | |
function DO_request(){ | |
// Actually, I should copy whole object without methods here cause of JSON | |
// chrome.extension.sendRequest(self, function(response) { | |
server.http(self, function(response) { | |
try{ | |
// console.log(JSON.parse(response.text)); | |
}catch(e){} | |
self.readyState = 4; | |
self.status = response.status || 200; | |
self.responseText = response.text || ""; | |
self.responseheaders = response.headers || {}; | |
if(self.onreadystatechange){ | |
self.onreadystatechange(self); | |
} | |
}); | |
} | |
if(self.asyn){ | |
window.setTimeout(DO_request, 0); | |
}else{ | |
DO_request(); | |
} | |
return self; | |
}; | |
XMLHttpRequest.prototype.abort = function(){return 1}; | |
XMLHttpRequest.prototype.rheaders = {}; | |
XMLHttpRequest.prototype.setRequestHeader = function(a, b){this.rheaders[a] = b; return;}; | |
XMLHttpRequest.prototype.getAllResponseHeaders = function(){return this.responseheaders;}; | |
XMLHttpRequest.prototype.getResponseHeader = function(a){return this.responseheaders[a]}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment