jquery UI自动完成下拉列表未显示(jquery UI autocomplete drop-down list not showing up)

我正在使用jquery UI自动完成,由于某种原因,我无法弄清楚为什么下拉列表没有显示。 我已经尝试过所有我无法想到的事情......我希望有些人可以帮助我。 Firebug从我的PHP脚本中显示正确的JSON输出。

成功的警报(数据)显示:[object Object]

HTML代码

<select name=key1 id=key1> <option selected value="">CHOOSE ONE </option> <option value="allrecs">ALL RECORDS <</option> <option value="citnumb">CIT NUMBER <<option> <option value="sernumb">SERIAL NUMBER </option> <option value="model">MODEL </option> </select> <input type="text" size=30 name="qvalue" id="qvalue">

JQUERY脚本

$("#qvalue").autocomplete( { source: function(request, response) { $.ajax( { url: "jqsuggest2.php", type: "POST", dataType: "json", data:{term: request.term,searchkey:$('#key1').val() }, success: function(data) { alert(data); response( $.map( data, function(item) { return { value: item.term } })); } }); }, minLength: 2 });

PHP脚本

$json = '['; $first = true; while($row = mysql_fetch_array($result)) { if (!$first) { $json .= ','; } else { $first = false; } if ($searchkey == "citnumb") { $json .= '{"value":"'.$row['citnum'].'"}'; } if ($searchkey == "sernumb") { $json .= '{"value":"'.$row['sernum'].'"}'; } elseif ($searchkey == "model") { $json .= '{"value":"'.$row['model'].'"}'; } } $json .= ']'; echo $json; }

Firebug输出 [{“value”:“28225”}]

任何帮助将不胜感激 谢谢 克里斯

I am using jquery UI autocomplete and for some reason I can't figure out why the drop-down list is not showing up. I've tried everything I can think of with no luck... I am hope some can help me. Firebug shows the correct JSON output from my PHP script.

The alert(data) under success shows: [object Object]

HTML code

<select name=key1 id=key1> <option selected value="">CHOOSE ONE </option> <option value="allrecs">ALL RECORDS <</option> <option value="citnumb">CIT NUMBER <<option> <option value="sernumb">SERIAL NUMBER </option> <option value="model">MODEL </option> </select> <input type="text" size=30 name="qvalue" id="qvalue">

JQUERY script

$("#qvalue").autocomplete( { source: function(request, response) { $.ajax( { url: "jqsuggest2.php", type: "POST", dataType: "json", data:{term: request.term,searchkey:$('#key1').val() }, success: function(data) { alert(data); response( $.map( data, function(item) { return { value: item.term } })); } }); }, minLength: 2 });

PHP script

$json = '['; $first = true; while($row = mysql_fetch_array($result)) { if (!$first) { $json .= ','; } else { $first = false; } if ($searchkey == "citnumb") { $json .= '{"value":"'.$row['citnum'].'"}'; } if ($searchkey == "sernumb") { $json .= '{"value":"'.$row['sernum'].'"}'; } elseif ($searchkey == "model") { $json .= '{"value":"'.$row['model'].'"}'; } } $json .= ']'; echo $json; }

Firebug output [{"value":"28225"}]

Any help would be greatly appreciated Thanks Chris

最满意答案

您需要将一个数组添加到source选项。 我相信如果你在map函数中更改return语句,你应该设置为go。 所以,改变

return { value: item.term }

return item.source

You need to have the an array to the source option. I believe if you change the return statement in your map function, you should be set to go. So, change

return { value: item.term }

to

return item.source

更多推荐

value,$json,电脑培训,计算机培训,IT培训"/> <meta name="description"