I'm attempting to write an easy Wordpress wordpress plugin, which updates a custom area value and batches it by one, after which echos the end result that is handed to my javascript code. For whatever reason, the information came back through the callback function has an additional appended towards the finish.

function like_post_callback() {
    $clicked = $_POST['clickedOn'];
    $id = $_POST['postID'];
    if($clicked == 0) $key = "like";
    else $key = "reallyLike";

    $prevLikes = get_post_meta($id, $key, true); //true, so we only return a single value
    $likes = 1;
    if($prevLikes == ""){
        add_post_meta($id, $key, $likes);
    } else{
        $likes = $prevLikes + 1;
        update_post_meta($id, $key, $likes);
    }

    echo $likes;
}

Here is what's calling it:

$.post("<?php bloginfo( 'wpurl' ); ?>/wp-admin/admin-ajax.php", 
{ action: "like_post", clickedOn: which, postID: "<?php the_ID(); ?>"}, function(data){
    alert(data);
    $("#" + clicked).html(text + " (" + data + ")");
});

Everything works, I simply come with an extra in data for whatever reason, and I'm not sure where it's originating from.

I desired to include die(); because the final line in like_post_callback because I desired to echo the end result and prevent the standard return value.

admin-ajax always return default '0' as output. Make use of die(); to prevent wordpress from calling its default function that returns zero. die(); will terminate the script coming back anything you echoed before that.