2011-04-16 53 views
1

我已成功地使用硬编码数组的自动完成功能。但是,当我尝试使用来自php文件的数据时,它不起作用。与JSON不工作的jquery自动完成

我的jquery如下。

<script type="text/javascript"> 
$(document).ready(function(){ 
    $("input#game_two_other").autocomplete({ 
     source: "mlb_other_teams.php", 
     minLength: 3 
    }); 
}); 
</script> 

我的php代码如下。

​​

任何想法或想法?

感谢,

兰斯

+0

没有ü尝试调试'$ json'尝试'echo $ json'并在'firebug'中看到 – diEcho 2011-04-16 07:19:37

+0

您能否请还张贴您的PHP脚本的输出? – nfechner 2011-04-16 07:19:56

+1

另外:您应该回到您的旧问题,并通过点击最有帮助的答案旁边的复选标记为他们选择答案。否则,人们可能不再帮助你。 – nfechner 2011-04-16 07:21:06

回答

1

当你产生了jQuery的JSON自动完成它具有containtains label和/或value属性:

$mister = mysql_query("SELECT * FROM al_other WHERE user_id = '".$_SESSION['id']."'") or die(mysql_error()); 

$json = array() 

while ($other = mysql_fetch_assoc($mister)) 
{ 

    $json[] = array('label'=>$other['team_one']); 
    $json[] = array('label'=>$other['team_two']); 

} 

echo json_encode($json); 

类似的问题:Having problems with jQuery UI Autocomplete

+0

谢谢。但是,它仍然不起作用 – Lance 2011-04-16 07:58:20

+0

你会得到什么样的错误? json现在看起来如何? – Dalen 2011-04-16 08:12:39

+0

看起来你应该加上'value'=> ...,但是希望@Lance能想出来。 – Milimetric 2011-04-16 09:50:54