unable to get wp_ajax hook to work in wordpress

//the homepage

$(document).ready(function(){

myplugin_cast_vote(20);

});




//the plugin

<?php
add_action('wp_head', 'myplugin_js_header' );

function myplugin_js_header() // this is a PHP function
{
  // use JavaScript SACK library for Ajax
  wp_print_scripts( array( 'sack' ));

  // Define custom JavaScript function
?>
<script type="text/javascript">
//<![CDATA[
function myplugin_cast_vote(posts)
{



    $.post("<?php bloginfo( 'wpurl' ); ?>/wp-content/themes/fullscreen/function.php", 
  {
    action : "process_thumbs" ,
    numposts : posts,
    results_div_id : output
  });    



} // end of JavaScript function myplugin_cast_vote

//]]>
</script>
<?php
add_action('wp_ajax_process_thumbs', 'my_action_callback');
add_action('wp_ajax_nopriv_process_thumbs', 'my_action_callback');
} // end of PHP function myplugin_js_header

?>


//functions.php


function my_action_callback(){
alert('sdfsdf');
$numposts = $_POST['numposts'];
$results_id = $_POST['results_div_id'];

die( "document.getElementById('$results_id').innerHTML = '$numposts'" );
}

I might not even sure my code is in the right place as I didnt really understand wordpress’s example.

The homepage executes the plugin function that makes the ajax call. I add the actions and direct it to the callback function in functions.php. Of course at that point the callback isn’t being run.

Read More

Any ideas?

Related posts

Leave a Reply

1 comment