Created
August 21, 2013 22:08
-
-
Save euforic/6300897 to your computer and use it in GitHub Desktop.
superagent XHR Titanium Shim
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
function XMLHttpRequest() { | |
// titanium xhr client | |
this._proxy = Ti.Network.createHTTPClient(); | |
// mapping for compatible functions | |
this.getResponseHeader = this._proxy.getResponseHeader; | |
this.open = this._proxy.open; | |
this.send = this._proxy.send; | |
this.setRequestHeader = this._proxy.setRequestHeader; | |
this.abort = this._proxy.abort; | |
} | |
Object.defineProperties(XMLHttpRequest.prototype, { | |
'onreadystatechange' : { | |
set: function (val) { | |
return this._proxy.onreadystatechange = val | |
} | |
}, | |
'readyState': { | |
get: function () { | |
return this._proxy.readyState; | |
} | |
}, | |
'responseText': { | |
get: function () { | |
return this._proxy.responseText; | |
} | |
}, | |
'responseXML': { | |
get: function () { | |
return this._proxy.responseXML; | |
} | |
}, | |
'status': { | |
get: function () { | |
return this._proxy.status; | |
} | |
} | |
}); | |
XMLHttpRequest.prototype.getAllResponseHeaders = function() { | |
return ''; | |
}; | |
this.XMLHttpRequest = XMLHttpRequest; | |
var location = this.location = {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@shobhit-shrivastava it is just a simple shim to make titaniums xhr library compatible with web xhr libraries. So if you just add it to your app.js you will be able to use libraries like superagent.js right out of the box.