twitter
    Find out what I'm doing, Follow Me :)
If you have any question, suggestion or article topic for me to write, feel free to contact me through my shout box. ;) Some time I need an idea to write. hehe Hopefully I can help you and share my expertise.

how to use wp_ajax in wordpress

last weekend I try to implement ajax in wordpress plugin. The problem is, there is no reference that I can get from wordpress wiki as well as their documentation to show the detail of how to use wp_ajax in wordpress.

How ever, here is the solution that i get how to use wp_ajax in wordpress.
Step 1.
You need to create callback function to handle ajax ( wp_ajax ) request.

function my_ajax_update(){
if (isset($_POST['c'])){
//you can do what ever here
}
}


Step 2.
create add_action using wp_ajax hook.

add_action("wp_ajax_your_action_name", "my_ajax_update");

your_action_name is action name that you'll submit using ajax post or get in Step 3.

Step 3.
on jQuery post..

url_action = \'' . get_bloginfo('wpurl') . '/wp-admin/admin-ajax.php\';
jQuery.post( url_action , { action:"your_action_name",c:"True" } ,function(data){
//your return result
});


continue... next post I will show you the full plugin code.

0 comments:

Post a Comment