Ajax in Plugins: returns the whole page

by huraji   Last Updated October 15, 2018 18:08 PM

I'm developing a small plugin for a client and my ajax calls returns the whole page as json response. I cannot find the bug.

In the plugin main.php:

function __construct(){
  //..
  $this->PluginSetup();
}

function PluginSetup(){
  //..
  add_action( 'wp_ajax_the_sag_form', array( $this , 'the_sag_form' ) );
}

function the_sag_form(){
  $reponse "hello";
  wp_send_json($response);
}

In my main.js:

function init_inpage_functions(){
    var PageData = new FormData();
    PageData.append('action', 'the_sag_form');
    $.ajax({
        method: 'post',
        url: ajaxurl,
        dataType: 'json',
        data: PageData,
        processData: false,
        contentType: false,
        beforeSend:function(data){

        },
        success:function(data) {
            console.log(data);
        },
        error: function(data){

        }
    });

}

What's wrong? In the response I just received the whole page. Thanks.



Related Questions





How to reset, reinit wordpress wpColorPicker?

Updated August 02, 2017 09:08 AM