我正在wordpress上向我的表单提出AJAX请求,但是在控制台中出现此错误:
jquery.min.js?ver = 5.2.1:2 POST https:/wp-admin/admin-ajax.php 400(echo 0)send @ jquery.min.js?ver = 5.2.1:2 < br /> ajax @ jquery.min.js?ver = 5.2.1:2(匿名)@ custom.js?ver = 1:32
派遣@ jquery.min.js?ver = 5.2.1:2
v.handle @ jquery.min.js?ver = 5.2.1:2
functions.php:
wp_localize_script(
'jsform', 'phpVars', array('ajaxurl' => admin_url('admin-ajax.php' ) ) );}
add_action( 'wp_enqueue_scripts', 'mcd_b_js' );
JS:
if (busy)
busy.abort();
busy = $.ajax({
url: phpVars.ajaxurl,
type: 'POST',
data: form.serialize(),
success: function(response) {
console.log('ok');
}
});
}```
答案 0 :(得分:0)
请检查phpVars.ajaxurl值。该值应为https://yourdomain.com/wp-admin/admin-ajax.php。您可以通过
获得该值