I've got a custom controller in my plugin that checks whether or not the request is ajax or not, using craft()->request->isAjaxRequest()
In the event that it is, I just want it to return a partial. First though, I'm trying to just get it to return a string but seem to be having issues getting something as simple as that to work (I'm pretty new to PHP). The code I have on the condition of it being an ajax request is:
$path = craft()->path->getSiteTemplatesPath();
craft()->path->setTemplatesPath($path);
$temp = craft()->templates->render('notifications/_test');
echo $temp;
I'm logging the response in javascript but keep getting a 404. If I try to open the link (custom controller url) in a new tab (so not and ajax request) it correctly executes the non ajax condition.
The GET request looks like this: $.get($(this).attr('href'), function(data)...
where the href is the controller action url.
Does anything look amiss? Am I perhaps missing a step to allow for this to work? I've tried $allowAnonymous
on the controller to no avail.