I had a situation where I wanted to receive the rendered page via ajax by first checking a jwt auth token, then user rights before turning the report around. Having the ability to direct the assets to a public directory while keeping my other pages private is really nice, but the only way I see documented to turn around JSON is by sending back the datastore('some_ds_name')->toJson, which I did not find to be particularly useful. The underlying problem is if my headers say I am sending back json data, but the rendered page is echoed or printed without being encoded, then despite my xhr request being status 200 or 201 my xhr is now invalid.
As a workaround to this situation, I retained the ability to utilize the built-in view rendering using the myreport->run()->render() by using the output buffer to suppress the automatic output when a page is rendered. This is similar to how other output options are handled, but I wanted to throw this out there for anyone else who might find it useful.
ob_start();
$someVar = new someClass;
$someVar->render()->run();
$data = ob_get_contents();
ob_end_clean();
$data = json_encode($data);
Now you can send back the data and use JSON.stringify on the data key client-side.
$response = json_encode(
array(
"jwt" => $jwt,
"data" => $data
)
);
echo $response;
I havent tested all features with this approach but it works for my purposes.