简体   繁体   English

DevBridge自动补全

[英]DevBridge autocompletion

im trying to use DevBridge Autocomplete downloaded from https://www.devbridge.com/sourcery/components/jquery-autocomplete/ 我正在尝试使用从https://www.devbridge.com/sourcery/components/jquery-autocomplete/下载的DevBridge自动完成

But i cant get it to work :( 但我不能让它工作:(

I have a HTML input field looking like this: 我有一个HTML输入字段,如下所示:

<input type="text" name="city" size="12" value="City" id="autocomplete" autocomplete="off">

In the same file i got my JavaScript: 在同一文件中,我得到了JavaScript:

<script src="autocomplete/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="autocomplete/jquery.mockjax.js" type="text/javascript"></script>
<script src="autocomplete/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
$('#autocomplete').autocomplete({
    serviceUrl: '/cities.php',
    onSelect: function (suggestion) {
        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
    }
});
</script>

An example output of cities.php?autocomplete=aach looks like this: city.php?autocomplete = aach的示例输出如下所示:

{ "suggestions": [ { "value": "Aach ", "data": "Aach " },{ "value": "Aacha ", "data": "Aacha " },{ "value": "Aachen ", "data": "Aachen " } ] } 

What am i missing? 我想念什么? Thx for help! 谢谢!

it might be the url issue , try instead of cities.php?autocomplete=aach the "cities.php?query=aach" request. 可能是网址问题,请尝试使用“ cities.php?query = aach”请求,而不要使用cities.php?autocomplete=aach I think by default jquery-autocomplete sends some_url?query=key_word . 我认为默认情况下jquery-autocomplete发送some_url?query=key_word

Check the Devbridge documentation. 查看Devbridge文档。 It specify that if want to change the query string parameter name then you have to set the paramName option. 它指定如果要更改查询字符串参数名称,则必须设置paramName选项。

In your case set it as while initializing the autocomplete widget: 在您的情况下,将其设置为初始化自动完成小部件时:

paramName:"autocomplete"

Line from Documentsation: 来自文档的行:

paramName : Default query . paramName :默认query The name of the request parameter that contains the query. 包含查询的请求参数的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM