小弟初学php, 想用ajax的方式填充数据
$sql = select * from jw_fance where . $condition;
$rs = mysql_query ( $sql, $conn );
$index = 0;
while ( ($row = mysql_fetch_array ( $rs )) != false ) {
$result[$index] = array (
pk => $row [pk],
name => $row ['name'],
short_name => $row ['short_name'],
node => $row ['node'],
parent_node => $row ['parent_node']
);
$index++;
// 下面的方式怎么也不行, mysql_fetch_array不是返回的是数组吗?
// $result[$index] =$row ;
}
请大侠指点一下, php+jquery传递数据,如何最方便, js端如何获取,谢谢。。。
------解决方案--------------------
最后要echo json_encode($result);,js才能解释到啊。
------解决方案--------------------
不是 js 如何读取,而是 js 需要的是什么样的数据
不能把困难留给别人
------解决方案--------------------
引用:quote: 引用:
最后要echo json_encode($result);,js才能解释到啊。
我也是新学,请问你这句,应该是生成json吧?
yes
------解决方案--------------------
$result[$index] =$row ; 这句也是可以的,你print_r($result); 就可以看到。只不过同时包含关联和索引数组。
php与js传递数据当然是json最方便。你可以这样写:
while ( ($row = mysql_fetch_assoc ( $rs )) != false ) {
$result[] = $row;
}
echo json_encode($result);
然后在js里就可以处理json了。
