Created
April 19, 2012 14:00
-
-
Save megoth/2421167 to your computer and use it in GitHub Desktop.
graphite.loader.xhr
This file contains 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
/*global graphite*/ | |
(function (graphite, loader, proxy) { | |
"use strict"; | |
var xhr = function (options) { | |
this.options = graphite.extend({ | |
"asynchronous": true, | |
"method": "GET", | |
"uri": window.location | |
}, options); | |
this.req = new XMLHttpRequest(); | |
if (this.options.success) { | |
send.call(this, this.options.success); | |
} | |
}; | |
xhr.prototype = { | |
abort: function () { | |
this.req.abort(); | |
}, | |
send: send | |
}; | |
function send(callback) { | |
var obj = this; | |
this.req.open(this.options.method, this.options.uri, this.options.asynchronous); | |
this.req.onerror = function () { | |
if (obj.options.proxy) { | |
obj.options.success = callback; | |
return graphite.create(proxy, obj.options); | |
} | |
callback("There was an error making the request\n"); | |
}; | |
this.req.onload = function () { | |
callback(null, obj.req.responseText, obj.req.status, obj.req); | |
}; | |
this.req.send(); | |
} | |
loader.xhr = xhr; | |
return xhr; | |
}(graphite, graphite.loader, graphite.loader.proxy)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment