Обратите внимание, что я получаю в консоли:
POST http://localhost/mysite/wp-admin/admin-ajax.php
400 (неверный запрос)
Functions.php: зарегистрировать файл JS и локализовать скрипт
function my_scripts_method() {
wp_register_script('custom_script',
get_stylesheet_directory_uri() . '/js/jquery_test.js',
array('jquery'),
'1.0' );
wp_enqueue_script('custom_script');
wp_localize_script( 'custom_script', 'custom_script_object', array(
'ajax_url' => admin_url( 'admin-ajax.php' )
));
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
Файл jquery_test.js:
var $j = jQuery.noConflict();
$j(function(){
$j(".small-board-profile-member").click(function(){
var fgfdgds = $j(this).attr('value');
console.log(fgfdgds);
$j('.modal-body').attr('value', fgfdgds);
$j.ajax({
url : custom_script_object.ajax_url,
type : 'post',
data : {
post_id : fgfdgds
},
processData: false,
contentType: false,
success : function( response ) {
$j('.rml_contents').html(response);
console.log("it worked");
}
});
});
});
Моя функция php для обработки запроса ajax (помещена в functions.php):
add_action( 'wp_ajax_my_action', 'my_action' );
function my_action() {
global $wpdb; // this is how you get access to the database
$whatever = ( $_POST['post_id'] );
//$whatever += 10;
echo $whatever;
wp_die(); // this is required to terminate immediately and return a proper response
}
Я считаю, что проблема заключается в функции php для обработки запроса ajax.Большое спасибо за ваше время !!!