Created
July 30, 2009 14:52
-
-
Save swannodette/158725 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
Browser.Request = function(){ | |
return $try(function(){ | |
return new GM.Request(); | |
}, function(){ | |
return new XMLHttpRequest(); | |
}, function(){ | |
return new ActiveXObject('MSXML2.XMLHTTP'); | |
}); | |
}; | |
var GM = {}; | |
GM.Request = new Class({ | |
name: "GM.Request", | |
initialize: function(force) | |
{ | |
if(!GM_log && !force) | |
{ | |
throw Error(); | |
} | |
this.headers = {}; | |
}, | |
__onreadystatechange__: function(responseDetails) | |
{ | |
this.status = responseDetails.status; | |
this.statusText = responseDetails.statusText; | |
this.responseHeaders = responseDetails.responseHeaders; | |
this.responseText = responseDetails.responseText; | |
this.readyState = responseDetails.readyState; | |
if(this.onreadystatechange && $type(this.onreadystatechange) == 'function') this.onreadystatechange(); | |
}, | |
open: function(method, url) | |
{ | |
this.method = method; | |
this.url = url; | |
}, | |
setRequestHeader: function(key, values) | |
{ | |
this.headers[key] = value; | |
}, | |
getResponseHeader: function(key) | |
{ | |
return this.responseHeaders[key]; | |
}, | |
send: function(data) | |
{ | |
GM_xmlhttpRequest({ | |
method: this.method, | |
url: this.url, | |
headers: this.headers, | |
data: data, | |
onreadystatechange: this.__onreadystatechange__.bind(this) | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment