Plugin Controller Ajax Request I've got a custom controller in my plugin that checks whether or not the request is ajax or not, using craft()-&gt;request-&gt;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()-&gt;path-&gt;getSiteTemplatesPath();
craft()-&gt;path-&gt;setTemplatesPath($path);
$temp = craft()-&gt;templates-&gt;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.
You can't echo out of the controller function. Though, you can send back the rendered template via a convenient controller function.

$this-&gt;renderTemplate('notifications/_test');


To add variables for your template to access (because it's not automatic for security reasons). You can do this.

$this-&gt;renderTemplate('notifications/_test', array(
    'message' =&gt; $message
));