Need help understanding how jQuery autocomplete script works

Dear fellow web developers:

I am a junior web developer, and I found the following autocomplete script online that uses jQuery, and PHP:

http://loopj.com/jquery-tokeninput/

I like it very much (the facebook script in particular), and I am trying to reverse engineer it to understand how it works (not the jquery file, but the html and php code).  However, I'm a little confused as to how this is working because on the one hand I see the list of tv shows listed inside the code of demo.html, but the items in the menu that drop down, don't reflect those values, so these values are clearly coming from someplace else.  Can someone please explain to me how this script functions using the php file that it works with?

Thanks in advance to all who reply.
fsyedAsked:
Who is Participating?
 
PragmatiCoderConnect With a Mentor Commented:
Inside demo.html go to line 62, you'll see this piece of code
        <script type="text/javascript">
        $(document).ready(function() {
            $("#demo-input-facebook-theme").tokenInput("http://shell.loopj.com/tokeninput/tvshows.php", {
                theme: "facebook"
            });
        });
        </script>

Open in new window


Now if you go to http://shell.loopj.com/tokeninput/tvshows.php, you'll see the list of show json encoded. So if you want to implement it on your own site, you'll have to do something very similar, which is actually explained in the Installation and setup on the very link you posted


Create a server-side script (PHP, Rails, ASP.net, etc) to generate your search results. The script can fetch data from wherever you like, for example a database or a hardcoded list. Your script must accept a GET parameter named q which will contain the term to search for. E.g. http://www.example.com/myscript?q=query

Your script should output JSON search results in the following format:

[
    {"id":"856","name":"House"},
    {"id":"1035","name":"Desperate Housewives"},
    ...
]
0
 
fsyedAuthor Commented:
Thanks very much for your help!

Take care.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.