DD I want to make a field with auto-complete in the search, i.e. a person starts typing a word search and automatically displays a list of close by value. I use the following code:

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 

where availableTags is a list of values ​​that will be automatically substituted later. I call <1input type="text" class="search" id="tags"> and everything works with a bang. I wanted to ask how instead of the variable availableTags accessed the file, which will have a list of all the relevant words. Sincerely. Waiting for an answer.

ps New to jquery, kick not kick)

    3 answers 3

    Reading an XML file with jQuery

      Well, it's not necessary to use xml ... moreover, if the content is static, then the ideal solution is good old txt. Just register in the txt file all the words you need and on .ready make an AYAX request, then simply break the data into an array and you will be happy :)

      If the autocomplete content is dynamic - then ajax'om on the same .ready to make a request not only to the static txt file but already to the php script, then generally it would be ideal to use JSON.

      small example:

        function myFunction (data) {
           alert (data);  // actually here we already have a string from the file
               // well, then for example, the string can be divided into an array using .split ()
               // in general it is up to you :)
       }
       $ (document) .ready (function () {
           $ .get ("/ public / css / main.css", myFunction);
       });
      

      • everything would be fine, I’m just telling me new to jquery how to describe it all. - duddeniska

      Http://api.jquery.com has excellent jQuery documentation. Specifically in your case read http://api.jquery.com/jQuery.get/ , especially about the dataType.