i'm trying to use ajax with a simple example, i took the example from : http://ocaoimh.ie/2008/11/01/make-your-wordpress-plugin-talk-ajax/ example N°5
(which doesn't work actually as it is)
So i'm trying just to get the result from the php page, located in /wp-content/ajax-php.php, but nothing, except the alert, seems to react. Could you have a look and tell me if you see something wrong? :
<?php
/*
Plugin Name: ajax with images
Plugin URI: http://ocaoimh.ie/
Description: A simple hello world plugin, taken from <a href="http://jquery.bassistance.de/jquery-getting-started.html#rate">here</a>
Version: 0.1
Author: Donncha O Caoimh
Author URI: http://ocaoimh.ie/
*/
function helloworld5_scripts() {
global $current_user;
if( !$current_user->ID )
return;
if( is_single() ) {
wp_enqueue_script('jquery');
}
}
add_action( 'wp_print_scripts', 'helloworld5_scripts');
function helloworld5_head() {
global $current_user;
if( !$current_user->ID )
return;
if( !is_single() )
return;
?>
<script type='text/javascript'>
<!--
var currentpost = '';
jQuery(document).ready(function() {
// generate markup
var ratingMarkup = ["Please rate: "];
for(var i=1; i <= 5; i++) {
ratingMarkup[ratingMarkup.length] = "<a href='#'>" + i + "du-texte-pour-tester</a> ";
}
// add markup to container and applier click handlers to anchors
jQuery("#rating").append( ratingMarkup.join('') ).find("a").click(function(e) {
//e.preventDefault();
// send requests
alert('ok');
jQuery.post("/wp-content/ajax-php.php", {rating: jQuery(this).html()}, function(data) {
jQuery("#rating").append(data+' : hello ');
} );
return false;
});
});
// -->
</script>
<?php
}
add_action( 'wp_head', 'helloworld5_head' );
function add_thumb_to_post( $content ) {
global $post;
global $current_user;
if( !$current_user->ID )
return $content;
if( !is_single() )
return $content;
return $content . "<p><div id='rating'></div></p><script type='text/javascript'>\n<!--\ncurrentpost='{$post->ID}';\n//-->\n</script>";
}
add_action( 'the_content', 'add_thumb_to_post' );
?>
Thanks
