I’m working on getting jQuery UI autocomplete to work from a remote datasource. http://jqueryui.com/demos/autocomplete/#remote
The sample code calls a php script search.php
$(function() {
$( "#birds" ).autocomplete({
source: "search.php",
minLength: 2
});
});
First lines from code snippet from search.php
$q = strtolower($_GET["term"]);
if (!$q) return;
$items = array( //set a bunch of key-value pairs);
What exactly does $q = strtolower($_GET["term"]); mean? Doesn’t !q always evaluate as true causing the .php script to return, thus preventing the rest of the script from executing?
EDIT
As a reference if you go to http://jqueryui.com/download and download the autocomplete package, the exact example I’m referring to is referenced in
- development-bundle/demos/autocomplete/search.php
- development-bundle/demos/autocomplete/remote.html
The strtolower call takes the query string variable term and converts it into lower-case; e.g. search.php?term=TEST results in ‘test’ being saved in $q. If you’re retreiving data from a case-sensitive source then you may want to do this to ensure term values of both ‘test’ and ‘TEST’ return the same data.
!$q tests whether $q doesn’t have a value; be that because it wasn’t passed in the URL or it was empty (search.php?term=).
You can test this logic with the following:
Output: