Jquery自动完成:源重定向到控制器

时间:2013-06-06 14:02:46

标签: javascript jquery autocomplete

我有以下代码块工作:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>autocomplete demo</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
</head>
<body>

<label for="autocomplete">Select a programming language: </label>
<input id="autocomplete">

<script>
$( "#autocomplete" ).autocomplete({
  source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ],
   select: function( event, ui ) {alert("sélectionné")}
});
</script>

</body>
</html>

但是,我需要将源重定向到控制器!例如'/ index / autocomplete' 我找不到合适的语法 谁能帮我 ?感谢

1 个答案:

答案 0 :(得分:0)

文档中有perfect example如何将自动完成插件与远程数据源一起使用:

$("#autocomplete").autocomplete({
    source: "/index/autocomplete",
    minLength: 2,
    select: function( event, ui ) {
        console.log( ui.item ?
            "Selected: " + ui.item.value + " aka " + ui.item.id :
            "Nothing selected, input was " + this.value 
        );
    }
});