//only allow ajax requests
if( !OW::getRequest()->isAjax() )
{
throw new Redirect404Exception();
exit;
}
So it means if this is NOT a ajax request then redirect to the 404exception
//magic method to handle ajax requests
public function ajaxResponder( )
{
//only allow ajax requests
if ( !OW::getRequest()->isAjax() )
{
throw new Redirect404Exception();
//there is no need to exit; request is already handled by another controller
//exit();
}
//check if ajax function is specified
if ( isset($_POST['ajaxFunc']) )
{
$callFunc = (string)$_POST['ajaxFunc'];
//call ajax function within the class
$result = call_user_func(array($this, $callFunc), $_POST);
}
else
{
//throw error 404 if ajax function is not specified
throw new Redirect404Exception();
}
//print ajax response
header('Content-Type: application/json');
exit(json_encode($result));
}
//test ajax function. You can create as many function as you like and call them the same way we will call this function.
public function test()
{
return "hello, test";
}
From you JavaScript, you can proceed to do this:
//submit request to our test function and log response
$.post('yourbestite.com
/pluginkey/controller/ajax-responder', {ajaxFunc:'test'}, function(response){console.log(response);
});
<a href="https://www.chojnow.pl/">infos asas</a>
<a href="">[infos asas](https://www.chojnow.pl/)</a>
infos asas
[infos asas](https://www.chojnow.pl/)
[url=https://www.chojnow.pl/]infos asas[/url]