I am demoing bit of JavaScript in a WordPress blog post that randomly produces some content. I'd like the user to be able to click a button and regenerate new random content via the script, and I'd like to do it asynchronously. Does anyone have experience getting AJAX elements to work WITHIN WordPress blog posts? Or is there a simpler method to achieve an equivalent asynchronous update panel?
+1
A:
Send your requests to this url - example.com/wp-admin/admin-ajax.php
with atleast one parameter as - action=[action name]
now make a plugin that has -
add_action('wp_ajax_[action name]', myfunction);
function myfunction()
{
// do stuff
}
more details here - http://codex.wordpress.org/AJAX%5Fin%5FPlugins
Arpit Tambi
2009-08-20 16:32:41
That particular method applies only to the admin, however the link provides details for getting AJAX from the viewer side. Thanks!
Derek
2009-08-20 17:45:41
will work wonderfully on the viewer side.. try out.
Arpit Tambi
2009-08-20 20:21:24