我已经读了几十篇关于这个错误的帖子,但我仍然不明白。因此,我想补充一下关于ajax 400的讨论。这是一个插件,用于显示/验证/记录一个名为shortcode的简单表单。
根插件文件如下所示:
add_menu_page(
\'Able Signup\', // page title
\'Able Signup\', // menu title
\'manage_options\', // capability (role of who can use)
\'able_signup\', // menu slug
\'able_signups\', // function in .php app that gets called when clicking
\'dashicons-clipboard\', // icon
4 // position in menu
);
require_once ( "apps/view_signups.php"); //for later dump of DB
require_once ( \'apps/save_signups.php\' ); //process submitted form <== ???
}
add_action( \'admin_menu\', \'wpdocs_register_able_signup_menu_page\' );
// starting of a shortcode
function able_show_form_template( $atts ) {
require_once ( \'apps/form_signups.php\' );
ob_start();
able_display_form_template( $atts ); //name of function called
return ob_get_clean();
}
add_shortcode( \'add_signup_form\', \'able_show_form_template\' ); // [add_signup_form id=\'01\']
?>
表单页面上的ajax如下所示:
$j(\'#signup\').on(\'submit\', function(){
//console.log("submit fired"); //works
//console.log("ajax_url"); //set in functions.php and works
$j.ajax({
type: \'POST\',
url: ajax_url,
data: {
action: \'save-form\',
full_name: $j(\'#full_name\').val(),
//more data
},
success: function (response) {
//stuff
}
});
return false;
});
最后,调用PHP文件进行处理:
// in apps/save_signups.php
function save_form() {
if ( wp_verify_nonce( $_POST[\'signup_nonce\'], \'\' ) ) {
//process form
wp_send_json( $messages );
wp_die();
} else {
wp_send_json( "Bad form" );
}
}
add_action( \'wp_ajax_save_form\', \'save_form\' );
add_action( \'wp_ajax_nopriv_save_form\', \'save_form\' );
Apache错误。日志显示了这一点,但没有多大意义:
ndefined offset: 0 in /var/www/susites/abledesignbuild/htdocs/wp-includes/class-wp-query.php on line 3284\'
我错过了什么?我唯一能想到的是
save_signups.php
不是“;参见;但不知道怎么说。
谢谢布拉德