Jqueryui Autocomplete and php

Posted on 2010-08-20
Last Modified: 2012-05-10
I want to be able to autocomplete an input box from a remote php script.
Say for example, I had a script which got a variable from the *post* and was able to produce an array based on what was posted, how do I return and use the results in Jquery autocomplete widget.


//do the magic here

$array=('item 1','item 2', 'item 3', 'etc');

Open in new window

how would I use the above script to autocomplete a standard input box, would I need to output it as json and would I need to set headers etc?

<form action ='search.php' method='post'>
<input type='text' class='search' name='q'>

Open in new window

Question by:jdav357
  • 3
LVL 82

Expert Comment

ID: 33490273
you may use implode :

Check an example here :
$array = array('item 1', 'item 2',  'item 3', 'etc');
echo implode("\n", $array);

Open in new window


Author Comment

ID: 33490884
ok, but how do I use this in the jquery and do I need to output it as json etc?
LVL 82

Accepted Solution

leakim971 earned 500 total points
ID: 33491171
for basic needs you don't need to play with the data :

LVL 82

Expert Comment

ID: 33501920
Thanks for the points!

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now