• Sometime recently my WordPress plugin started failing in my DEV environment (on two different boxes) on an AJAX call. What I see is that when I call:

    $t = json_encode(<somearray>);

    an extraneous ‘+’ character is inserted into the output buffer. I observed this by viewing the result of an ob_get_content() call. $t shows the correct JSON results, and the contents of somearray doesn’t seem to matter.

    It is happening in the context of a callback function registered as an wp_ajax_my_action hook.

    function my_action_callback() {
        // tested example
        $a = array("a" => "orange", "b" => "banana", "c" => "apple");
        echo json_encode($a);
        die(); // this is required to return a proper result
    }
    ...
    add_action('wp_ajax_my_action', array( $cemeteriat_plugin, 'my_action_callback' ) );

    I can assign the results of json_encode to a variable instead of echoing, and the results are fine, but checking the output buffer at that point shows a single ‘+’ already inserted.

    Not sure where to look next

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘wp_ajax_my_action hook with json_encode puts extraneous ' ' in output buffer’ is closed to new replies.