I'm trying to write a plugin that when called on /something returns a JSON, something like {"payload": {...}}.
At the moment I have create a plugin that calls onPageInitialized. The dump shows the correct payload but it loads the 404 template. If I call the route via AJAX I get a 404 response instead of 200.
--- php
public function onPageInitialized()
{
$resp = array("payload" => array("test" => "yay"));
$resp = json_encode($resp);
dump($resp);
return $resp;
}
How can I make the plugin return a status of 200 and just the JSON, no template, nothing, just plain text?