user1261156
user1261156

Reputation: 11

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. If I remove $(function(){ in the code there is no error but still no data in autocomplete.

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']

Upvotes: 0

Views: 2837

Answers (1)

dbf
dbf

Reputation: 3453

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
    });
});

Upvotes: 1

Related Questions