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(){

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

function the_sag_form(){
  $reponse "hello";

In my main.js:

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

        success:function(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