我需要一个用于jquery catcomplete的 json ,我希望你能帮助我......
我有这个代码
$( ".autocomplete" ).autocomplete({
source: "files/news.php?listar=json"
});
我希望“files/news.php?listar=json”显示如下内容:
[
{ label: "title1", category: "category1" },
{ label: "title2", category: "category2" }
]
请你帮助我好吗?
@编辑:
我试过这个,但没有奏效:
if ($_GET['listar'] == 'json')
{
echo '['."\n";
$query = mysql_query("SELECT * FROM noticias WHERE deletada='0' ORDER BY id DESC");
$a = 0;
while ($noticia = mysql_fetch_array($query))
{
echo ' { label: "'.$noticia['titulo'].'", category: "'.ucwords(Categoria($noticia['categoria'])).'" }';
$a++;
if ($a < mysql_num_rows($query))
{
echo ",\n";
}
}
echo "\n".']';
exit;
}