1

我在使 jQuery 的结果Autocomplete可点击时遇到问题。首先这是我在 php 文件中的内容:

$q = strtolower($_GET["term"]);    
$return = array();    
$query = mysql_query("SELECT id,title,unique_name,product FROM products WHERE product LIKE '%$q%' AND active='1' LIMIT 11") or die(mysql_error());    
while ($row = mysql_fetch_array($query)) {    
    array_push($return,    
array('label'=>$row['product'],    
'value'=>'./shop/index.php?product="'.$row['unique_name'].'">'.$row['product']));    
}    
echo(json_encode($return));    

我需要添加到数组 url 作为参数吗?

我通过将 url 作为值传递到数组中来做到这一点是否正确?

这是我的http://jsfiddle.net/Lszkb/4/包含其余的 js 和 html .. 请帮我解决这个问题。我发现了很多关于这个问题的问题,但没有一个给我答案。还有别的东西 - window.location 根本不起作用..谢谢你们的任何帮助和建议

4

1 回答 1

0

您的代码在要指定的对象值方面存在多个问题。

我以某种方式试图通过以 JSON 格式传递 Ajax 请求来找到解决方案。

 source: function (request, response) {
        $.ajax({
            url: "your link",
            dataType: "json",
            data: {
                style: "full",
                maxRows: 12,
                name_startsWith: request.term
            },

your link在测试时将其替换为您的。我希望它有效。

以下工作示例:http: //jsfiddle.net/Lszkb/8/

如果您想以不同的方式接近,请告诉我,只需在评论中指定即可。

于 2013-04-14T21:55:02.610 回答