I\'d like to detect if the browser made a request via AJAX (AngularJS) so that I can return a JSON array, or if I have to render the template. How can I do this?
There isn't any way to be certain whether a request is made by ajax.
What I found that worked for me, was to simply include a get parameter for xhr requests and simply omit the parameter on non-xhr requests.
For example:
example.com/search?q=Boots&api=1
example.com/search?q=Boots