Php 钛Appcelerator-如何提取远程数据
我使用下面的代码来提取数据,但什么都没有发生。这是我的PHP代码Php 钛Appcelerator-如何提取远程数据,php,json,titanium,Php,Json,Titanium,我使用下面的代码来提取数据,但什么都没有发生。这是我的PHP代码 $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=
$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);
sendit.open('GET','http://myurl.com/mypages.php');
sendit.send();
sendit.onload=函数(){
var json=json.parse(this.responseText);
var json=json.pages;
var dataArray=[];
var-pos;
对于(pos=0;pos
当我运行应用程序时,我得到的只是一张空白表。任何帮助都将不胜感激 您正在将数组嵌入另一个数组中,因此在javascript方面:
dataArray.push({title:'' + json.pages[pos].pagename + ''});
^^^^^ - missing level
您应该在send.send之前先send.onload 我还建议您实现sendit.onerror方法,以及中间Ti.API.debug(stuff);
您还加倍了json的声明,它正在工作,但不是很好。您是否尝试移动
sendit.send()下面的代码>发送它。是否打开
在onload事件中添加日志,以确保它完全被触发
它在中指出,必须在调用open之前定义onload,才能注册它。我更改了顺序,但它不起作用。另外,我在脚本中有onerror方法,它不会给我错误。你有像wireshark这样的嗅探器吗?您能够进入调试模式吗?请尝试:dataArray.push(Ti.UI.createTableViewRow({title:''+json[pos].pagename+''}))代码>所以我猜在json.pages中有0行。您是否使用导航器检查过php结果?这必须是一个Json问题,而不是钛合金问题。请检查Json数组长度或是否超过示例Json字符串