Identify angular js AJAX calls in ASP.NET MVC code

前端 未结 1 1595
温柔的废话
温柔的废话 2021-02-19 11:03

I am working on a sample application using ASP.NET MVC and AngularJS.

In server side code , I have written a Action filter attribute , and in that I need to check whethe

相关标签:
1条回答
  • It decides by looking whether X-Requested-With header exists or not. You can add X-Request-With header manually to $http service.

    Individual request

    $http.get('/controller/action', {
       headers: {
        'X-Requested-With': 'XMLHttpRequest'
       }
    });
    

    For every request

    app.config(['$httpProvider', function ($httpProvider) {
      $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
    }]);
    

    You can see why it is missing from Angular

    0 讨论(0)
提交回复
热议问题