Title: Using Jquery inside wordpress plugin
Last modified: August 22, 2016

---

# Using Jquery inside wordpress plugin

 *  Resolved [Hercal](https://wordpress.org/support/users/hercal/)
 * (@hercal)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/)
 * hello ,
 * i have a plugin that contain a function to get insert/get data from DB .
    my 
   question is how can i use jquery or link any other JS inside wordpress . i search
   and found many article but it is not clear , please i nead steps to add jquery
   file in my plugin ,
 * appropriate your support

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

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559474)
 * jQuery is already loaded in the dashboard. Don’t load the library twice.
 *  Thread Starter [Hercal](https://wordpress.org/support/users/hercal/)
 * (@hercal)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559477)
 * hi andrew ,
    ok , another inquiry please , i call this plugin using shortcode,
   where can i write my jquery code ?
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559483)
 * For just a few lines you are asking quite a large question.
 * The database is on the server side, with WordPress it is accessed by PHP code.
   Jquery is a javascript technique that runs in browsers on the client side.
 * You are asking for your client side code to converse with the server side code.
   This is readily done using a technique called AJAX, much of the interactive WordPtress
   dashboard code uses AJAX, this is how the progressive saves of Page / Post entries
   is done just by way of example.
 * You will find many AJAX examples and tutorials on the web and around WordPress,
   you should be able to find some plugins that use AJAX + jquery + database query/
   updates. Try and find a small and simple one so that the details does not swamp
   the principles. I suggest that you develop your plugin in small incremental steps.
 * You will find that you are using quite a range of languages depending upon the
   context, in one project I used: PHP,javascript,html,css,SQL. To this you would
   be adding jquery.
    I used firebug to help with the debugging on the browser side,
   in one tool it shows you your javascript execution, html and css. For the PHP
   I used an editor and a web based syntax verifier.
 * I understand that adding jquery requires adding the appropriate script libraries
   to the page header, best done in a custom page template.
    My projects have been
   relatively simple, I judged that it was better for me to stay with javascript,
   if I was already familiar with jquery I would have used it.
 * Answering your pt: 3
    Your jquery code is housed in your plugin directory, you
   enque it into the page header in your custom page template.
 *  Thread Starter [Hercal](https://wordpress.org/support/users/hercal/)
 * (@hercal)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559488)
 * thank you so much but please check this topic and i will be very thankful if 
   you know why this code not working
 * [http://stackoverflow.com/questions/27379102/using-jquery-inside-wordpress-plugin](http://stackoverflow.com/questions/27379102/using-jquery-inside-wordpress-plugin)
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559501)
 * Sorry, at a quick reading I didn’t see your problem.
    BUT I did see what will
   be future problems.
 * When you do something like this:
 *     ```
       $var = $_POST['id'];
        $query="select id,CountryCode,City from _city where CountryCode='$id'";
        $result=$wpdb->get_results($query);
       ```
   
 * You are just begging for someone to enter a country name like:
    `x';drop table;`
 * The solution is to use prepare to scrub your user input.
    This is called an SQL
   injection attack. The WordPress support people spend a lot of time ensuring that
   themes and plugins and WordPress core do not have this vulnerability.
 * Here is a cartoon about this:
    [http://xkcd.com/327/](http://xkcd.com/327/)
 *  Thread Starter [Hercal](https://wordpress.org/support/users/hercal/)
 * (@hercal)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559612)
 * RossMitchell , my problem solved but yes you are right ,i know sql injection 
   and i can avoid it it .NET platform using sql parameters or stored procedures,…
   but i don’t know how to avoid it using wordpress, any suggested links to read
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559631)
 * `but i don't know how to avoid it using wordpress`
 * In the reference to the wpdb class, there are several examples using the prepare
   method, just search for “$wpdb->prepare(” in this doc:
    [http://codex.wordpress.org/Class_Reference/wpdb](http://codex.wordpress.org/Class_Reference/wpdb)
 * This precaution is easily enough to do that I routinely use it in development,
   there is no cause to put it off and polish it later.
 *  Thread Starter [Hercal](https://wordpress.org/support/users/hercal/)
 * (@hercal)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559633)
 * I will , thanks for advice

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

The topic ‘Using Jquery inside wordpress plugin’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [Hercal](https://wordpress.org/support/users/hercal/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/using-jquery-inside-wordpress-plugin-1/#post-5559633)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
