Title: Jquery Autocomplete Source
Last modified: August 31, 2016

---

# Jquery Autocomplete Source

 *  Resolved [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * (@cimatadev)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/)
 * Hi,
 * I have some trouble to use autocomplete with jquery.
 * I think that the function works because I can find this in my code :
 * `<ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content" id="
   ui-id-1" tabindex="0" style="display: none;"></ul>`
 * But the results do not display because I have this error :
    Fatal error: Call
   to a member function prepare() on null in /home/clients/717b0e9cd144e922df74206711a41135/
   web/cimaya/wp-content/themes/cimaya/autocomplete.php on line 19
 * /autocomplete.php
 *     ```
       function get_liste_resultat_reference( $q = '' ) {
         global $wpdb;
         $sql = $wpdb->prepare(...);    <- line 19
       }
       ```
   
 * /inc/main.js
 *     ```
       $('#rech-nav').autocomplete({
         source: $.get('/cimaya/wp-content/themes/cimaya/autocomplete.php'),
         appendTo: "#rech-nav",
         autoFocus: true,
         minLength: 2,
       });
       ```
   
 * I think that the problem is wpdb.
 * Can someone help me ? I am becoming crazy !
 * Thanks !!
 * PS : Sorry for my english

Viewing 12 replies - 1 through 12 (of 12 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320755)
 * It appears as though “$wpdb” is empty.
 *  Thread Starter [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * (@cimatadev)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320759)
 * “$wpdb” is supposed to work every where, no ?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320761)
 * Not if you’re targeting a file in your theme directly without using WordPress.
 *  Thread Starter [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * (@cimatadev)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320766)
 * I am sorry, I did not understand
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320768)
 * You put your file inside the theme directory, but that does not mean you are 
   using WordPress. You are effectively calling the file as if it were outside of
   WordPress.
 *  Thread Starter [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * (@cimatadev)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320771)
 * Now I get it, thanks !
 * How can I fix it ? Because I can not move my file out the theme directory and“
   $wpdb” works in every other files so I do not know how to make it work in this
   one.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320780)
 * > works in every other files so I do not know how to make it work in this one.
 * Are you sure? Try targeting one of these files (that you think works) and see
   if the “wpdb” variable is defined:
 *     ```
       $('#rech-nav').autocomplete({
         source: $.get('/cimaya/wp-content/themes/cimaya/[the-other-file].php'),
         appendTo: "#rech-nav",
         autoFocus: true,
         minLength: 2,
       });
       ```
   
 *  Thread Starter [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * (@cimatadev)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320788)
 *     ```
       $('#rech-nav').autocomplete({
         source: $.get('/cimaya/wp-content/themes/cimaya/thematique.php'),
         appendTo: "#rech-nav",
         autoFocus: true,
         minLength: 2,
       });
       ```
   
 * Fatal error: Call to a member function get_row() on null in /home/clients/717b0e9cd144e922df74206711a41135/
   web/cimaya/wp-content/themes/cimaya/thematique.php on line 21
 * That is weird because this other file actually works on my site but not when 
   I am targeting it in autocomplete
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320792)
 * I don’t think you understood what I meant by “You are effectively calling the
   file as if it were outside of WordPress”. Maybe I didn’t word it right.
 * You are not using WordPress, so $wpdb will never exist. You think you are using
   WordPress because you put the file in the theme directory, but you are not using
   WordPress.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320795)
 * Follow this article: [https://codex.wordpress.org/AJAX_in_Plugins](https://codex.wordpress.org/AJAX_in_Plugins)
 *  Thread Starter [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * (@cimatadev)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320799)
 * > You are not using WordPress, so $wpdb will never exist.
 * How can I use WordPress, so $wpdb will exist ?
 *  Thread Starter [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * (@cimatadev)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320817)
 * I added :
 * `require_once('../../../wp-load.php' );`
 * in my PHP script and it worked !
 * Thanks for your help !

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Jquery Autocomplete Source’ is closed to new replies.

## Tags

 * [jquery](https://wordpress.org/support/topic-tag/jquery/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 12 replies
 * 2 participants
 * Last reply from: [cimatadev](https://wordpress.org/support/users/cimatadev/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/jquery-autocomplete-source/#post-7320817)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
