我在我的网站的搜索控制台中收到这种错误代码:
wp-admin / admin-ajax.php?action = process_simple_like&nonce = 39ac08d186&post_id = 108&disabled = true&is_comment = 0
如何修复它们?
答案 0 :(得分:0)
我遇到类似的错误。我已经尝试了所有方法,但得到了400(错误请求)。
我的php代码:
wp_enqueue_script( 'ajax-my-followers', PLUGIN_URL . 'assets/js/a_ajax.js', array('jquery'),'0.5', false );
wp_enqueue_script('ajax-my-followers');
wp_localize_script('ajax-my-followers', 'postCustom', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'redirecturl' => home_url()
));
public function __construct() {
add_action( 'wp_ajax_nopriv_my_followers_ajax', [ $this, 'my_followers_ajax' ] );
add_action( 'wp_ajax_my_followers_ajax', [ $this, 'my_followers_ajax' ] );
}
Javascript:
(function ($) {
$(document).ready(function () {
// Perform AJAX form submit
$('#getmyfollowers').on('click', function (e) {
e.preventDefault();
// $('#loading').html('loading...');
var dataString = {action: 'my_followers_ajax'};
$.ajax({
type: "POST",
url: postCustom.ajaxurl,
data: dataString,
success: function (data) {
//$('#loading').html(data);
console.log(data);
},
error: function (errorThrown) {
console.log(errorThrown);
}
});
});
}); // end ready
})(jQuery);
错误:
POST http://wp.localhost/wp-admin/admin-ajax.php 400(错误请求)