Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I try to do some autocomplete on my site. I found solution using jQuery:

$(function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
});

And it works fine, but I need to load data form text file. I need a way to make var availableTags from text like:

ruby
java
javascript

and so on.

share|improve this question
1  
Use an AJAX server script to read the file and generate the completion entries. The jquery autocomplete documentation shows how to do this. –  Barmar Dec 23 '13 at 17:48
add comment

1 Answer

up vote 2 down vote accepted

You should be able to use a simple get request and split the result on new lines. I'd use $.get().

$.get('languages.txt', function(txtFile){
  var languages = txtFile.split("\n");
  $("#tags").autocomplete({
    source: languages
  });
});
share|improve this answer
    
so simple :) looks even better now :) a long long way before me :) –  user3130327 Dec 24 '13 at 7:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.