Skip to content

Instantly share code, notes, and snippets.

@darkwing
Created February 15, 2013 22:38
var xhr = new XMLHttpRequest({
mozSystem: true
});
// To enable xhr.abort if user cancels
outReq.xhr = xhr;
outReq.oncancel = function() {
this.xhr.abort();
}
xhr.open('GET', remote, true);
xhr.responseType = 'json';
xhr.timeout = fb.operationsTimeout || fb.DEFAULT_TIMEOUT;
xhr.onload = function(e) {
if (xhr.status === 200 || xhr.status === 400 || xhr.status === 0) {
if (callback && typeof callback.success === 'function')
self.setTimeout(function() {
callback.success(xhr.response);
},0);
}
else {
self.console.error('FB: HTTP error executing query. ',
query, ' Status: ', xhr.status);
if (callback && typeof callback.error === 'function')
self.setTimeout(callback.error, 0);
}
} // onload
xhr.ontimeout = function(e) {
self.console.error('FB: Timeout!!! while executing query', query);
if (callback && typeof callback.timeout === 'function')
self.setTimeout(callback.timeout, 0);
} // ontimeout
xhr.onerror = function(e) {
self.console.error('FB: Error while executing query: ', query,
': ', e);
if (callback && typeof callback.error === 'function')
self.setTimeout(function() {
callback.error(e);
},0);
} // onerror
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment