Last active
March 7, 2017 12:57
-
-
Save TimDorand/66f86f50c06ad7812456b01f7e114171 to your computer and use it in GitHub Desktop.
Request callback Titanium
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
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