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:

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.
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("", {
                theme: "facebook"

Open in new window

Now if you go to, 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,, 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.

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

    {"id":"1035","name":"Desperate Housewives"},
fsyedAuthor Commented:
Thanks very much for your help!

Take care.
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.