Skip to content

Instantly share code, notes, and snippets.

@appcdr
Created August 29, 2011 15:45
Show Gist options
  • Save appcdr/1178667 to your computer and use it in GitHub Desktop.
Save appcdr/1178667 to your computer and use it in GitHub Desktop.
Appcelerator: HTTPClient and JSON sample app
Ti.UI.backgroundColor = '#dddddd';
var url = "https://raw.github.com/appcelerator/Documentation-Examples/master/HTTPClient/data/json.txt";
var win = Ti.UI.createWindow();
var table = Ti.UI.createTableView();
var tableData = [];
var json, fighters, fighter, i, row, nameLabel, nickLabel;
var xhr = Ti.Network.createHTTPClient({
onload: function() {
// Ti.API.debug(this.responseText);
json = JSON.parse(this.responseText);
for (i = 0; i < json.fighters.length; i++) {
fighter = json.fighters[i];
row = Ti.UI.createTableViewRow({
height:'60dp'
});
nameLabel = Ti.UI.createLabel({
text:fighter.name,
font:{
fontSize:'24dp',
fontWeight:'bold'
},
height:'auto',
left:'10dp',
top:'5dp',
color:'#000',
touchEnabled:false
});
nickLabel = Ti.UI.createLabel({
text:'"' + fighter.nickname + '"',
font:{
fontSize:'16dp'
},
height:'auto',
left:'15dp',
bottom:'5dp',
color:'#000',
touchEnabled:false
});
row.add(nameLabel);
row.add(nickLabel);
tableData.push(row);
}
table.setData(tableData);
},
onerror: function(e) {
Ti.API.debug("STATUS: " + this.status);
Ti.API.debug("TEXT: " + this.responseText);
Ti.API.debug("ERROR: " + e.error);
alert('There was an error retrieving the remote data. Try again.');
},
timeout:5000
});
xhr.open("GET", url);
xhr.send();
win.add(table);
win.open();
@pundu55
Copy link

pundu55 commented Feb 27, 2014

@tona: do you want to capture the label from the row and display in the new window?

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