How to enable withCredentials to flag on XMLHttpRequest in AngularJS for “Access-Control-Allow-Origin”

Ahamed Fazil Buhari
SharePoint Developer
Published On :   09 Jan 2018
Visit Count
Today :  4    Total :   161
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial

Hi everyone,

In this article we will see how to enable withCredentials config in you Angular project. Before going further let us see the requirement of using withCredentials, in the following link you can find the description of withCredential -

 angular.module("App", [])
     .controller("Ctrl", function ($scope, $http) {
         var URL = "https://mywebapi/api/names";
         var requestHeader = {
             getHeader: {
                 'headers': {
                     'accept': 'application/json;odata=verbose'
         var result = $http.get(URL, requestHeader.getHeader)
             .then(function (response) {
                 var data = JSON.parse(;
                 $scope.values = data
                 return data;
     .config(['$httpProvider', function ($httpProvider) {
         $httpProvider.defaults.withCredentials = true;
Happy Coding


SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.

Migratiin Tools for SharePoint