我不断得到回应0
而不是string
, 这是我的功用。为什么?
代码来自functions.php
// enque test.js
function add_script() {
wp_enqueue_script(
\'test\',
get_stylesheet_directory_uri() . \'/js/test.js\',
array( \'jquery\' )
);
wp_localize_script(\'test\', \'ajax_object\', array( \'ajax_url\' => admin_url( \'admin-ajax.php\' )));
}
add_action( \'wp_enqueue_scripts\', \'add_script\' );
// ajax function
function my_AJAX_processing_function(){
echo \'string\';
}
add_action(\'wp_ajax_nopriv_ACTION_NAME\', \'my_AJAX_processing_function\');
代码来自
test.js
$(function () {
var data = {
action: \'ACTION_NAME\'
};
jQuery.post(ajax_object.ajax_url, data, function(response) {
alert(\'Got this from the server: \' + response);
});
});