我正在开发一个WordPress插件来进行短代码和查看PowerBI报告。我有json文件中的所有数据。我已经测试了文件和功能代码。WordPress代码没有问题。下面的AJAX中有一些错误,在控制台中显示以下错误。
POST: http://localhost/xxx/wp-admin/admin-ajax.php [HTTP/1.1 400 Bad Request 418ms]
以下是jQuery代码:
jQuery(document).ready( function(){
jQuery(\'.subjectdiv\').on(\'click\', \'a.acaret\', function(e) {
e.preventDefault();
var rml_post_id = jQuery(this).attr( \'mydata\' );
jQuery.ajax({
url : mypowerbi_ajax.ajax_url,
type : \'post\',
data : {
action : \'powerbi_manager_ajax\',
_ajax_nonce: mypowerbi_ajax.check_nonce,
post_id : rml_post_id
},
success : function( response ) {
jQuery(\'.powerbitabwindow\').html(response);
}
});
});
});
下面是函数及其代码
function fn_powerbi_manager($atts) {
wp_enqueue_style(\'bootstrapstyle\', plugins_url(\'/powerbi_manager/assets/css/bootstrap.min.css\'), __FILE__);
wp_enqueue_script(\'bootstrapscript\', plugins_url(\'/powerbi_manager/assets/js/bootstrap.min.js\'), __FILE__);
wp_enqueue_style(\'powerbistyle\', plugins_url(\'/powerbi_manager/assets/css/style.css\'), __FILE__);
wp_enqueue_script(\'jqueryscript\', plugins_url(\'/powerbi_manager/assets/js/jquery.min-v3.5.1.js\'), __FILE__);
wp_enqueue_script(\'powerbiscript\', plugins_url(\'/powerbi_manager/assets/js/scripts.js\'), __FILE__);
add_action(\'wp_enqueue_scripts\', \'bootstrapstyle\');
add_action(\'wp_enqueue_scripts\', \'bootstrapscript\');
add_action(\'wp_enqueue_scripts\', \'powerbistyle\');
add_action(\'wp_enqueue_scripts\', \'jqueryscript\');
add_action(\'wp_enqueue_scripts\', \'powerbiscript\');
wp_register_script( \'myajax-script\', plugins_url( \'assets/js/ajaxcall.js\', __FILE__ ), array(\'jquery\'), null, true );
wp_enqueue_script( \'myajax-script\' );
wp_localize_script( \'myajax-script\', \'mypowerbi_ajax\', array( \'ajax_url\' => admin_url(\'admin-ajax.php\'), \'check_nonce\' => wp_create_nonce(\'powerbi_manager_nonce\') ));
require_once plugin_dir_path( __FILE__).\'templates/frontend-page.php\';
}
function my_powerbi_manager_ajax()
{
check_ajax_referer( \'powerbi_manager_nonce\' );
$rml_post_id = $_POST[\'post_id\'];
$json = file_get_contents(plugins_url(\'/powerbi_manager/json/powerbimanager.json\'));
$decoded_json = json_decode($json, true);
$shortcodedata = array();
foreach ($decoded_json as $rkey => $jsondata){
if ($jsondata[\'visualidentifier\'] == $rml_post_id){
$shortcodedata[] = $jsondata[\'shortcode\'];
}
}
echo do_shortcode($shortcodedata[0]);
}
if (function_exists(\'my_powerbi_manager_ajax\'))
{
add_action( \'wp_ajax_powerbi_manager_ajax\', \'my_powerbi_manager_ajax\' );
}
add_shortcode(\'powerbi-manager\', \'fn_powerbi_manager\');
谁能找出错误或给我建议?提前感谢