我正在使用下面的代码来拉取数据,什么也没有发生。这是我的PHP代码。钛Appcelerator - 如何拉取远程数据
$getall = "SELECT * FROM pages WHERE account_id=$id ORDER BY course_id";
$showall = @mysqli_query ($dbc, $getall); // Run the query.
$json = array();
if (mysqli_num_rows($showall) > 0)
{
while ($row=$showall->fetch_assoc()) {
$json[]=array(
'logged' => true,
'pagename'=>$row['pagename'],
);
} // end while
header("Content-Type: text/json");
echo json_encode(array('pages' => $json));
}
而这里是我的JS代码运行的应用程序。
sendit.open('GET', 'http://myurl.com/mypages.php');
sendit.send();
sendit.onload = function(){
var json = JSON.parse(this.responseText);
var json = json.pages;
var dataArray = [];
var pos;
for(pos=0; pos < json.length; pos++){
dataArray.push({title:'' + json[pos].pagename + ''});
// set the array to the tableView
tableview.setData(dataArray);
};
};
var tableview = Ti.UI.createTableView({
});
currentWin.add(tableview);
当我运行的应用程序,我得到的只是一张空白表。任何帮助将不胜感激。
检查你的json数组长度或过去的样品JSON字符串 – Triode 2012-02-23 18:42:14