Using wp_send_json to return HTML

I can’t tell what the $my_page, $my_page, or $shipHelper variables are supposed to do, but you can use an output buffer to capture the output of your DisplayEventInfoBox function. You can try the following:

function myAJAXFn() {
    ob_start();
    DisplayEventInfoBox($my_page, $shipHelper);
    $my_html = ob_get_contents();
    ob_end_clean();
    wp_send_json_success( array('page'=>$my_html) );
}

Leave a Comment