Created
October 4, 2014 01:36
-
-
Save lbrenman/baf1a9c0d7ea0b50ec53 to your computer and use it in GitHub Desktop.
Appcelerator Titanium Node.ACS Post Example
This file contains 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
{ | |
"routes": [ { | |
"path": "/", | |
"callback": "application#index" | |
}, { | |
"path": "/getData", | |
"method": "post", | |
"callback": "services#getData" | |
} ], | |
"filters": [ { | |
"path": "/", | |
"callback": "" | |
} ], | |
"websockets": [ { | |
"event": "", | |
"callback": "" | |
} ] | |
} |
This file contains 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
$.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(); |
This file contains 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
<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> |
This file contains 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 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