1

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.

1
  • 1
    Use an AJAX server script to read the file and generate the completion entries. The jquery autocomplete documentation shows how to do this. Commented Dec 23, 2013 at 17:48

1 Answer 1

2

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

1 Comment

so simple :) looks even better now :) a long long way before me :)

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.