[英]jQuery autocomplete problems with ajax - TypeError: this.source is not a function
I'm using the jQueryUI autocomplete function it works fine with data from a local variable but when using data from a $.get request i'm getting the following error: TypeError: this.source is not a function. 我正在使用jQueryUI自动完成功能,它可以很好地处理来自本地变量的数据,但是当使用来自$ .get请求的数据时,出现以下错误:TypeError:this.source不是函数。 If I remove $(function(){ in the code there is no error but still no data in autocomplete. 如果我在代码中删除$(function(){,没有错误,但自动完成中仍然没有数据。
Content in: index.html
<script>
$(function(){
var ajaxData;
$.get('ajaxdata.html', function(data) {
$('.result').html(data);
console.log('Load was performed.'+data);
ajaxData = data;
});
var localData = ['ActionScript','AppleScript','Scheme'];
$( "#tags" ).autocomplete({
//source: localData //working
source: ajaxData //not working
});
});
</script>
<input id="tags">
Content in: ajaxdata.html
['ActionScript','AppleScript','Scheme']
For example: 例如:
// use document ready
$(document).ready(function(){
$.get('ajaxdata.html', function(data) {
$('.result').html(data);
console.log('Load was performed.'+data);
$( "#tags" ).autocomplete({
source: data
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.