我试图用一个简单的例子来使用ajax,我的例子来自:http://ocaoimh.ie/2008/11/01/make-your-wordpress-plugin-talk-ajax/ 示例N°5(实际情况并非如此)
因此,我只是想从位于/wp-content/ajax-php中的php页面获得结果。php,但除了警报之外,似乎什么都没有反应。如果你看到什么不对劲,你能看一下告诉我吗
<?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\' );
?>
谢谢