Angularjs $Http Json Call To Yii Backend

To get Yii to set


From AngularJS I had to add a header ‘X-Requested-With’ : ‘XMLHttpRequest’



   method: 'GET',

   url: url,

   headers: {

	'Content-type': 'application/json',

        'X-Requested-With' : 'XMLHttpRequest' // Needed by Yii to look at it as ajax request.



success(function(data, status, headers, config) {

If anyone knows of a better way please share.

you can config your app to send this header for all requests

myAppModule.config(['$httpProvider', function($httpProvider) {

    $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';


fix($http): remove ‘X-Requested-With’ from header defaults