Permalink
Browse files

Got sample working on iPhone sim and iPod Touch, updated JSON

  • Loading branch information...
Tony Lukasavage
Tony Lukasavage committed Aug 29, 2011
1 parent 3b047ea commit 255afd8da6a0c17779404953d7adf2017d5fecca
Showing with 53 additions and 7 deletions.
  1. +45 −7 HTTPClient/Resources/app.js
  2. +8 −0 HTTPClient/data/json.txt
@@ -1,20 +1,58 @@
Ti.UI.backgroundColor = '#dddddd';
-var url = "http://savagelook.com/knucklehead/ff.php?firstname=kazu"
+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() {
- alert('success');
+ 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'
+ });
+ nickLabel = Ti.UI.createLabel({
+ text:'"' + fighter.nickname + '"',
+ font:{
+ fontSize:'16dp'
+ },
+ height:'auto',
+ left:'15dp',
+ bottom:'5dp'
+ });
+ 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.');
},
- onerror: function() {
- alert('error');
- }
+ timeout:5000
});
-xhr.setTimeout(5000);
xhr.open("GET", url);
-//loadingView.show();
xhr.send();
+win.add(table);
win.open();
View
@@ -31,6 +31,14 @@
{
"name": "Wanderlei Silva",
"nickname": "The Axe Murderer"
+ },
+ {
+ "name": "Gearges St. Pierre",
+ "nickname": "Rush"
+ },
+ {
+ "name": "Manny Pacquiao",
+ "nickname": "Pac-Man"
}
]
}

0 comments on commit 255afd8

Please sign in to comment.