Skip to content

Instantly share code, notes, and snippets.

@iskugor
Last active December 28, 2015 06:09
Show Gist options
  • Save iskugor/7455044 to your computer and use it in GitHub Desktop.
Save iskugor/7455044 to your computer and use it in GitHub Desktop.
Use parse.com JS API in Titanium mobile
module.exports = {
getItem : function(_key) {
return Ti.App.Properties.getObject(_key);
},
setItem : function(_key, _value) {
return Ti.App.Properties.setObject(_key, _value);
},
removeItem : function(_key, _value) {
return Ti.App.Properties.removeProperty(_key);
}
};
var Parse = require("parse").Parse;
Parse.initialize(app_id, javascript_key);
function XMLHttpRequest() {
this._client = Ti.Network.createHTTPClient({
autoEncodeUrl: false,
timeout: 5000
});
var _this = this;
this._client.onreadystatechange = function() {
_this._onreadystatechange();
};
this._client.onerror = function() {
_this.onerror();
};
};
XMLHttpRequest.prototype = {
open: function(method, url, async) {
this._client.open(method, url, async);
},
setRequestHeader: function(key, value) {
this._client.setRequestHeader(key, value);
},
send: function(data) {
this._client.send(data);
},
_onreadystatechange: function() {
if (this.onreadystatechange) {
this.readyState = this._client.readyState;
this.status = this._client.status;
this.responseText = this._client.responseText;
this.onreadystatechange();
}
},
onerror: function() {
if (this.onreadystatechange) {
this.readyState = this._client.DONE;
this.status = this._client.status;
this.responseText = this._client.responseText;
this.onreadystatechange();
}
}
}
exports.XMLHttpRequest = XMLHttpRequest;
@iskugor
Copy link
Author

iskugor commented Nov 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment