Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Jqueryui Autocomplete and php

Posted on 2010-08-20
4
Medium Priority
?
525 Views
Last Modified: 2012-05-10
Hi,
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.

searchajax.php

$post=$_POST['q'];
//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'>
<!-etc-->
</form>

Open in new window


cheers
John
0
Comment
Question by:jdav357
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33490273
you may use implode : http://www.php.net/manual/en/function.implode.php

Check an example here : http://www.thewhyandthehow.com/jquery-autocomplete/
$array = array('item 1', 'item 2',  'item 3', 'etc');
echo implode("\n", $array);
?>

Open in new window

0
 
LVL 2

Author Comment

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

Accepted Solution

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

$("#field").autocomplete("path/to/function.php");
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33501920
Thanks for the points!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

721 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