Note that there are some explanatory texts on larger screens.

plurals
  1. POSomethings wrong with autocomplete
    primarykey
    data
    text
    <p>I'm building a website to learn coding and I have an autocomplete that is based on Jquery ui's that I'm populating by three mysql tables.</p> <p>Here's my code on index.php (the page where my search box is and autocomplete should be on)</p> <pre><code> &lt;script src="./public/js/jquery.js"&gt;&lt;/script&gt; &lt;script src="public/js/jquery-ui-1.8.22.custom.min.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script&gt; $(function() { $("#search").autocomplete({ source: "suggest.php", minLength = 2, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.value + aka " + ui.item.id : "Nothing selected, input was " + this.value ); } }); }); &lt;/script&gt; </code></pre> <p>Heres the code on index.php that is the form:</p> <pre><code>&lt;form class="form-search span8 offset6"&gt; &lt;input type="text" id='search' name='q' autocomplete="off" class="input-medium search-query"&gt; &lt;button type="submit" class="btn btn-warning"&gt;GO!&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Heres the code on suggest.php:</p> <pre><code>&lt;?php require("./config.php"); $q = $_GET['q']; $names = ''; $result = mysql_query("SELECT name FROM company WHERE name LIKE '$q%' UNION SELECT cat FROM cat WHERE cat LIKE '$q%' UNION SELECT subcat FROM subcat WHERE subcat LIKE '$q%' LIMIT 10"); $names = array(); while ($row = mysql_fetch_array($result)) { $names[] = $row['name']; } echo json_encode($names); ?&gt; </code></pre> <p>If I go directly to suggest.php?q=<strong>SOMETHING</strong> and echo out $names, this is what comes out:</p> <pre><code>["City Market","Cafes","Cheesesteaks","Chicken Wings","Chinese","CSA","Coffee &amp; Tea","Convenience Stores","Comedy Clubs"]Array </code></pre> <p>When I open the developer panel in Chrome there is an error next to the jQUery for the autosuggest saying "Uncaught SyntaxError: Unexpected Token ="</p> <p>My autosuggest isn't showing up. WHat's wrong?</p> <p>Thanks for all help!</p> <hr> <p>I changed the = to : and now the new error is "Unexpected Token Illegal" and the autocomplet still isn't showing up...Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload