Skip to content

Instantly share code, notes, and snippets.

@TimDorand
Last active March 7, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimDorand/66f86f50c06ad7812456b01f7e114171 to your computer and use it in GitHub Desktop.
Save TimDorand/66f86f50c06ad7812456b01f7e114171 to your computer and use it in GitHub Desktop.
Request callback Titanium
var request = Titanium.Network.createHTTPClient();
var done=false;
request.onload = function() {
try {
if (this.readyState == 4 || !done) {
done=true;
if(this.status===200){
var content = JSON.parse(this.responseText);
}else{
alert('error code' + this.status);
}
}
}
catch (err) {
Titanium.API.error(err);
Titanium.UI.createAlertDialog({
message : err,
title : 'Remote Server Error',
});
}
};
request.onerror = function(e) {
Ti.API.info(e.error);
};
request.open("POST", "http://test.com");
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send({ test: 'test'});
// Sources: http://stackoverflow.com/questions/26773261/how-we-get-and-post-api-in-titanium-alloy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment