0

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']
2
  • 1
    move the code for the creation of the autocomplete in the $.get callback function, the reason why it is not working is because an ajax request has an a-synchron, it has a different time scale as the rest of your javascript execution time Commented Sep 9, 2012 at 22:09
  • unable to edit my comment- ajax request has an a-synchone time scale :D Commented Sep 9, 2012 at 22:20

1 Answer 1

1

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
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.