Я создал плагин для Wordpress, и теперь я пытаюсь узнать Ajax in plugin.Неопределенный индекс в плагине Wordpress при вызове AJAX
Когда я называю свою функцию:
wp-admin/admin-ajax.php?action=my_action
Я получаю эту ошибку:
Notice: Undefined index: whatever
Это моя функция
add_action('admin_footer', 'my_action_javascript'); // Write our JS below here
function my_action_javascript() { ?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var data = {
'action': 'my_action',
'whatever': 1234
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
$.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
</script> <?php
}
и функции обратного вызова
add_action('wp_ajax_my_action', 'my_action_callback');
function my_action_callback() {
global $wpdb; // this is how you get access to the database
$whatever = intval($_POST['whatever']);
$whatever += 10;
echo $whatever;
wp_die(); // this is required to terminate immediately and return a proper response
}
Что вызывает эта ошибка и как ее исправить?
Убрано избыточное, пересмотрено для ясности. –