0

jQueryUI オートコンプリート関数を使用していますが、ローカル変数からのデータでは正常に動作しますが、$.get 要求からのデータを使用すると、次のエラーが発生します: TypeError: this.source は関数ではありません。コードで $(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']
4

1 に答える 1

1

例えば:

// use document ready
$(document).ready(function(){
  $.get('ajaxdata.html', function(data) {
    $('.result').html(data);

    console.log('Load was performed.'+data);

    $( "#tags" ).autocomplete({
      source: data
    });
});
于 2012-09-09T22:11:25.313 に答える