Jetoox
Jetoox

Reputation: 1437

jquery autocomplete unresponsive script

I'm creating a wordpress plugin where I'm trying to populate an autocomplete textbox using jquery and the source is from the database.

jquery script

$( "#tags" ).autocomplete({
        source: "<?php echo WP_PLUGIN_URL.'/plugin-name/php-file.php'?>"
    });

html

<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">

php

global $wpdb;
$code = $wpdb->get_results(
        "SELECT suburb as label, post_code as code
        FROM Sheet1
        ",ARRAY_A
        );  
echo(json_encode($code));

but when I run this, the script crashes.

What seems to be the problem?

Upvotes: 1

Views: 232

Answers (1)

Taha Paksu
Taha Paksu

Reputation: 15616

you didn't set the query filter:

global $wpdb;
$code = $wpdb->get_results(
    "SELECT suburb as label, post_code as code
    FROM Sheet1
    WHERE suburb like '%" . $_GET["term"] . "%'
    LIMIT 0,25
    ",ARRAY_A
    );  
echo(json_encode($code));

But of course you need to sanitize the $_GET["term"] part.

Upvotes: 1

Related Questions