Today the $http service that discovers the AngularJS framework provides the $http.get ()/$http. Post () in the AJAX request without the X-requested-with field.
In this case, the backend PHP will not be able to determine whether the accepted HTTP request is an AJAX request.
What to do, obviously it is to add this field to the HTTP request header .
1, AngularJS can be such a child :
I don ' t know well MVC3 and can set a custom header for all request from AngularJS.
Then on the server side you just has to get the this header and does what the want with the request from angular.
To has the custom header in AngularJS just does this:
Angular.module (' MyModule ', []) . config ([' $httpProvider ', function ($httpProvider) { $ httpprovider.defaults.headers.common["from-angular"] = "true"; }])
The for use of the x-requested-with you has to does this too:
$httpProvider. defaults.headers.common["X-requested-with"] = ' xmlhttprequest ';
It ' s not set by default anymore because a lot part of the community has to delete this header to enable CORS request
2,JQuery Ajax method also provides a way to set the HTTP request header;
JS in Ajax request when set HTTP request header in X-requestd-with= Ajax