使用php源代码进行Jquery自动完成

我想使用jquery自动完成“function”与php文件作为源。 我不明白为什么它不起作用。 如果我使用在变量中输入的数据一切正常。 希望有人能提供帮助。 提前感谢您的回复。 干杯。 渣。

我的HTML:

 

我的JS:

 $(function() { $( "#moi" ).autocomplete({ source: "php/search_loc.php", minLength: 2 }); }); 

我的PHP:

 <?php header('Content-Type: text/html; charset=utf-8'); require("../inc/connect.inc.php"); mysql_set_charset('utf8'); $result = mysql_query("SELECT * FROM search_loc"); $row=mysql_fetch_assoc($result); while($row=mysql_fetch_assoc($result)){ echo $row['srl_loc'].'
';} ?>

你的PHP脚本应该返回JSON数据,

在Jquery UI 自动完成文档中

 The datasource is a server-side script which returns JSON data, 

将其包装在json_encode()函数中:

 echo json_encode($row['srl_loc']).'
';