Skip to content

Instantly share code, notes, and snippets.

@lbrenman
Created October 4, 2014 01:36
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 lbrenman/baf1a9c0d7ea0b50ec53 to your computer and use it in GitHub Desktop.
Save lbrenman/baf1a9c0d7ea0b50ec53 to your computer and use it in GitHub Desktop.
Appcelerator Titanium Node.ACS Post Example
{
"routes": [ {
"path": "/",
"callback": "application#index"
}, {
"path": "/getData",
"method": "post",
"callback": "services#getData"
} ],
"filters": [ {
"path": "/",
"callback": ""
} ],
"websockets": [ {
"event": "",
"callback": ""
} ]
}
$.tf.addEventListener('return', function(e){
makeNodeCall($.tf.value);
});
function makeNodeCall(value) {
var url = "https://608eb7d2d47544a1b4fb97e08423659aef06e396.cloudapp-enterprise.appcelerator.com/getData";
if(Titanium.Network.networkType == Titanium.Network.NETWORK_NONE){
Ti.API.info("index: makeNodeCall() - No Network");
alert("No Network");
return;
}
var xhr = Titanium.Network.createHTTPClient({
onload: function() {
$.label.text = this.responseText;
},
onerror: function(e) {
alert("Error with API");
},
timeout: 10000,
});
xhr.open("POST", url);
xhr.send({data: value});
}
$.index.open();
<Alloy>
<Window class="container" layout="vertical">
<TextField id="tf" top="50" hintText="Enter text" color="black" left="10" width="Ti.UI.FILL"/>
<Label id="label" top="50" left="10" color="red" />
</Window>
</Alloy>
function getData(req, res) {
res.send(req.body.data+' is what you entered');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment