I don’t understand how to return HTML correctly via AJAX.
I have this routine
function DisplayEventInfoBox()
{ ?>
<div id="eventInfo">
<div class="avail-from cart-right">
<?php
and so on...
}
If I include this in an AJAX call and the end of the routine is a die() the response object contains the HTML, which I can use as I like.
function myAJAXFn() {
DisplayEventInfoBox($my_page, $shipHelper);
die();
}
I want to send additional information, for instance using wp_send_json_success or another variable.
This code returns the HTML with the JSON array tacked on to the end. I would like a create a JSON object where I can access my page property and the html. What’s the best way to do this?
function myAJAXFn() {
DisplayEventInfoBox($my_page, $shipHelper);
wp_send_json_success( array('page'=>$myPage) );
}