• Home
  • About
  • Work Portfolio
Blue Orange Green Pink Purple

Archive for the ‘WordPress Plugin’ Category

You can use the search form below to go through the content and find a specific post or page:

Jan 23

How to: Ajax in WordPress Plugin (Admin Panel)

Wordpress plugins are made on the WordPress administrative suite. When creating plugins you can make use of working with a huge library of functions and classes.

Creating Ajax to work with plugins on the admin panel side is quite straight forward. below is an example of how it could be coded.


add_action('admin_head', 'my_action_javascript');

function my_action_javascript() {
?>

jQuery(document).ready(function($) {

var data = {
action: 'my_special_action',
whatever: 1234
};

// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});

}

Now we need to create a response from the Ajax call. we do this by defining a handle using add_action and a wp_ajax_my_special_action property.

add_action('wp_ajax_my_special_action', 'my_action_callback');

function my_action_callback() {
global $wpdb; // this is how you get access to the database

$whatever = $_POST['whatever'];

$whatever += 10;

echo $whatever;

die();
}
?>

Noormohamed

  • About
    About me. Edit this in the options panel.
  • Photo Stream
  • Categories
    • CSS
    • Donate
    • Hosting
    • Java
    • jQuery
    • PL/SQL
    • VMWare
    • WordPress Plugin
  • Recent Articles
    • PL/SQL Basic Insert (no return)
    • VMWare Player on a VMWare ESX Guest
    • Java – do loop
    • Java – foreach equivalent
    • Java – while loop
    • Java – for loop
  • Archives
    • February 2010
    • January 2010
    • April 1999
  • Search






  • Home
  • About
  • Work Portfolio

© Copyright Noormohamed. All rights reserved.
Designed by FTL Wordpress Themes brought to you by Smashing Magazine

Back to Top