WordPress.org

Ready to get started?Download WordPress

Forums

Problem with admin-ajax.php adding '0' to the end of JSON response (5 posts)

  1. rsanchez112
    Member
    Posted 3 years ago #

    I'm having a peculiar problem with admin-ajax.php where anything I send it, it will return a '0' at the end of the response content. For exmample, I have in my code this:

    function myAjaxCallback() {
        print 1;
    }
    add_action('wp_ajax_myAjax', 'myAjaxCallback');

    The javascript side is like this:

    jQuery.post(ajaxurl, {action:'myAjax'}, function(result) {
        console.log(result);
    }

    In my debug message I would expect just '1', but I'm getting '10'. It happens no matter what I print in the ajax callback function. I have no idea what's doing this, so any help would be appreciated.

    Should also note that this is in a plugin I'm working on, and it's happening on both the post.php page and widgets.php page.

  2. rsanchez112
    Member
    Posted 3 years ago #

    Just wanted to bump this see if anyone has the same problem or has a solution.

  3. christian_gnoth
    Member
    Posted 3 years ago #

    the return value of the ajax call is 0 - you print the 1 and the response is appended

  4. Adam Harley
    Member
    Posted 3 years ago #

    You need to die() at the end of an AJAX handler function to prevent further content.

  5. henriquepalazzo
    Member
    Posted 3 years ago #

    Thanks Adam Harley! I was trying to solve this problem for at least 3 hours. It works for me.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags