I am trying to create an app which displays search results for a query as the user is typing similar to Google Instant. It doesn’t need to be under the search box like Instant but the idea is that relevant choices for a query appear as the user types.
Is there a way for me to use something similar?
Thanks
Here’s how I would solve the problem, using PHP and JavaScript.
You will first need to set up a server side resource to serve search results, ideally in json.
If you want to do this the right way, see this excellent tutorial on creating a REST API with PHP (it sounds like that’s the server side technology you’re using).
If you want to hack something together quickly that may not be as robust, here’s how:
First, create a php file at a given location, let’s say /api/search/search.php
It should look something like this:
This will return json formatted results when you do a GET request to /api/search/search.php?q=Your query here
You will need some client side code to party with the server. The basic approach is to set up an input box and every time the value changes, use jQuery’s AJAX methods ($.getJSON would work nicely here, but you could also use $.GET or $.AJAX), to send a request with the q parameter equal to the user’s query. You then attach a callback function that runs when the request is complete that parses the results and outputs them on the page. Some sample below.
Here’s the markup:
Good luck