Sunday, August 14, 2022
HomeWordPress Developmentadmin-ajax.php returns 0 even when the put up standing code is 200...

admin-ajax.php returns 0 even when the put up standing code is 200 OK


I’ve seen loads of comparable questions and I’ve included the suggestions from the solutions however nonetheless, the problem isn’t resolved.

Ajax request is shipped on click on of a button in js file.

WyrRoute.js

clickHandler(e) {
    var ajax_url = my_ajax_object.ajax_url
    var information ={
        'motion': 'my_action',
        'question_id': '10183'
    }
    $.ajax({
        kind: 'POST',
        url: ajax_url,
        information: information,
        dataType: 'json',
        success: perform (xhr, x, checkStatus) {
            console.log(xhr);
            console.log(checkStatus.standing)
            console.log("success")
        },
        error: perform(e) {
            console.log(e.statusText);
            console.log("failure")
        }
    });
}
}

Within the receiver.php file I’ve:

<?php 
    add_action( 'wp_enqueue_scripts', 'my_enqueue' );
    add_action( 'wp_ajax_my_action', 'my_action' );
    
perform my_enqueue() {
    wp_register_script( 'ajax-script', plugins_url( '/src/WyrRoute.js' , __FILE__ ), array('jquery') );
    wp_enqueue_script('ajax-script');
    wp_localize_script( 'ajax-script', 'my_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
perform my_action(){
   $theQuestion = $_POST['question_id'];
   echo $theQuestion;
   die();
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments