来自admin ajax的0状态。php表示未解析任何“操作”。
将要分配句柄的脚本排入队列时,在使用wp\\u localize\\u脚本时需要使用此句柄,此外,还需要分配url。https://codex.wordpress.org/Function_Reference/wp_localize_script
wp_register_script( \'some_handle\', \'path/to/myscript.js\' );
wp_localize_script( \'some_handle\', \'object_name\', array( \'ajax_url\' => admin_url( \'admin-ajax.php\' ) );
wp_enqueue_script( \'some_handle\' );
然后为了让JS正确调用URL
jQuery.ajax({
url : object_name.ajax_url,
type : "POST",
dataType: "json",
data : {
data : data,
action : "bakkah_register_session"
},
success : function(response){
jQuery(".message_register_bakkah").html(response);
jQuery("#bakkah_submit_button").removeAttr("disabled");
obj[0].reset();
console.log (response);
},
error: function(response) {
console.log(response);
}
});
此外,在PHP中,您还需要从函数中实际返回一些东西,以便jQuery进行处理,返回的任何内容都需要是json\\U编码的数组。
$whatever[\'type\'] = \'Success\';
$whatever[\'message\'] = \'Some returned msg string\';
返回json\\u encode($whatever);
在jQuery脚本中,您可以将这些值引用为response.type
和response.message
允许您执行检查。。。。
success : function(response){
if( response.type == \'success\') {
// do something
}
else {
// Failed, do something else
}
}