I want to load some dynamic data with jQuery after document load. For example, let it be tag cloud:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#sidebar-tags').load('<?php echo bloginfo('template_url'); ?>/tag_cloud.php');
});
</script>
And in tag_cloud.php something like this:
<? wp_tag_cloud(''); ?>
And ofcoz it doesn't work, "Internal server error". How can i make this idea work?
Solved:
Followed Plamen Nikolov's link, came up with this:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery.ajax({
type : "post",
dataType : "json",
url : "/wp-admin/admin-ajax.php",
data : ({action: "get_tag_cloud"}),
success: function(response) {
alert(response);}
})
});
</script>
and in functions.php:
add_action('wp_ajax_get_tag_cloud', 'get_tag_cloud');
add_action('wp_ajax_nopriv_get_tag_cloud', 'get_tag_cloud');
function get_tag_cloud() {
echo json_encode(wp_tag_cloud('echo=0'));
die();
}
It almost works: if I check it with Firebug, I can see the response, but the alert doesn't pop up.