jQuery.ajax() normally sends an X-Requested-With header with XMLHttpRequest set as the content. On the server (in PHP), I usually detect this by testing:
$is_ajax = $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'
In AngularJS, commonly found in $routeProvider.when(), you can obtain a template from the server with templateUrl: '/path/on/server'.
My problem is that templateUrl requests seem to not set X-Requested-With headers, so there's no way to distinguish templateUrl requests from any other type of request.
Is there any way to get $routeProvider to send X-Requested-With as XMLHttpRequest?
Reference:
$routeProvider Docs - (search
templateUrl)jQuery jqXHR - see
jqXHR.setRequestHeader("X-Requested-With", "XMLHttpRequest")Using Angular
v1.1.5via Google CDNUpdate: I found the actual commit where Angular developers removed
X-Requested-Withfrom$http.get. Wonder why they would do that?Update: https://github.com/angular/angular.js/issues/1004 - discussion where header was removed.