Jquery TokenInput没有加载结果

时间:2018-03-09 00:17:27

标签: javascript jquery jquery-tokeninput

我有:

$('.titulares').tokenInput("http://localhost/ajax/ajax.php",{
            tokenLimit: 1,
            queryParam: 'query',
            propertyToSearch: 'nome',
            resultsLimit: 2,
            tokenValue: 'id',
            noResultsText: 'Nada',
            searchingText: "Procurando...",
            hintText: "Buscar titular",
            method: 'GET',
            onResult(){
                alert('a');
            }           
        });

ajax.php JSON输出:

[  
   {  
      "id":12,
      "nome":"Joe Bill"
   },
   {  
      "id":13,
      "nome":"PJ"
   },
   {  
      "id":14,
      "nome":"John"
   },
   {  
      "id":16,
      "nome":"Acme"
   },
   {  
      "id":17,
      "nome":"Acme2"
   },
   {  
      "id":18,
      "nome":"Acme3"
   }
]

代码显示加载文本,但JSON输出未在文本字段中重新定义,并且onResult未被触发

谢谢

1 个答案:

答案 0 :(得分:0)

您的代码无效,因为您编写了错误的语法。如果你修复它,你的代码现在就会正常运行。

onResult: function(result){
                console.log(result);
            } 

演示:http://jsbin.com/yimiwumije/edit?html,js,output