Ajax request 400 bad request
-
Hi,
I’m developping a plugin which used to work but stop to work anymore, so i rebuild it from beginning but i still have the same problem with ajax, i always have an error 400.
My class constructor :
public function __construct(){ if(!is_admin()) { add_action('init', array($this,'init_button_frontend')); add_action('wp_enqueue_scripts', array($this, 'register_css_front'),15); add_action('wp_enqueue_scripts', array($this, 'register_js_front')); add_action('wp_ajax_nopriv_ajax_send_report', array($this, 'ajax_send_report')); add_action('wp_ajax_ajax_send_report', array($this, 'ajax_send_report')); } }
My registring function
function register_js_front() { wp_register_script( 'help2spell-js', plugin_dir_url( __FILE__ ).'js/help2spell.js', array( 'jquery' )); wp_enqueue_script( 'help2spell-js' ); wp_localize_script('help2spell-js','help2spell', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) )); }
My js :
var data = { 'action': 'ajax_send_report', 'closer_title': closer_title, 'post_id': post_id, 'mistake': mistake, 'correction': correction }; jQuery.ajax({ url: help2spell.ajax_url, method: 'post', data: data, success: function(response){ ... } });
The data are send correctly like i can see in the console :
action ajax_send_report closer_title post_id 6509 mistake emixer,+arrang correction dsqdqsdqs
My ajax function :
public function ajax_send_report(){ $mistake = $_POST['mistake']; $correction = htmlentities($_POST['correction']); $post_id = $_POST['post_id']; $closer_title = $_POST['closer_title']; $stmt = array(); if($this->mysql_report_insert($mistake, $correction, $post_id, $closer_title)){ echo '<span class="help2spell-message-success"><strong>'. __( "Successful registration !", 'help2spell') .'</strong><br/>'. __( "Thank you for your participation.", 'help2spell').'</span>' ; } else { echo '<span class="help2spell-message-error"><strong>'. __( "Ooops...", 'help2spell').'</strong><br/>'.__( "An error occurred while recording, please try again !", 'help2spell') .'</span>' ; } die; wp_die(); }
Off course i read all other topics with the same problem but i can’t find the problem…
If anybody have an idea of my mistake it could be very helpful…Thanks
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Ajax request 400 bad request’ is closed to new replies.