您的位置:首页 > Web前端 > JavaScript

利用Json向客户端发送数据

2009-11-24 14:43 253 查看
文件:sendto.php

<?php

$connect=mysql_pconnect("localhost","root","dbsc0901");

mysql_select_db("twiiq",$connect);

$query="SELECT * FROM quiz ORDER BY RAND() LIMIT 20";

$result=mysql_query($query);

$q = array ();
$i = 0;

while ($row = mysql_fetch_assoc($result))
{
$questions[$i] = array (
'description' => $row['question'],
'answers' => array (
'1' => $row['solu1'],
'2' => $row['solu2'],
'3' => $row['solu3'],
'4' => $row['solu4'],
'5' => $row['solu5'],
)
);
$i++;
}

$json_string = json_encode($questions);

($isXmlHttpRequest) ? header('Content-type: application/json') : header('Content-type: text/plain');
echo $json_string;

mysql_close($connect);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: