A question that I see come up often is why Angular’s
$http AJAX methods seem to be incompatible with server-side features in popular frameworks like ASP.NET MVC, Express, Django, and Rails that modify their responses for AJAX-based requests.
Examples range from partial rendering techniques like Rails’ Turbolinks (aka UpdatePanel 2.0) to endpoints that respond with nothing but a JSON representation of the page’s content instead of rendering HTML at all. A wide range of these sort of server-side features in various frameworks and libraries work that way, so the discrepancy between the behavior in Angular vs. client-side libraries like jQuery can be puzzling.
In this post, I’ll briefly explain the mechanism that your server-side framework uses to detect AJAX requests, show you how to make a single Angular
$http request compatible with that mechanism, expand that to automatically apply to all requests sent through any
$http method, and then explain why Angular doesn’t seem to work right by default.