UDAY SINGH
UDAY SINGH

Reputation: 13

How to set withCredentials:false in angularjs and expressjs application

  $scope.status = function()
  {
    $http({url:'url', method:"GET", withCredentials: false, headers:{
         'Authorization': 'Token ' + token,
      }
    })
    .success(function(result) {
        console.log("Success", result);
        $scope.resultGet = result;
        alert("success");
    })
    .error(function(error, status, header, config) {
        $scope.error = { message: error, status: status};
        console.log($scope.error, config);
    });
}

I have tried above method to set withCredentials:false.But not reverting any changes.It always take withCredentials:true.

Hence I get error."'XMLHttpRequest cannot load "API url". Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://localhost:3000' is therefore not allowed access.'"

I have also tried with set withCredentials:false in expressjs.Using cors(). But no changes.

Upvotes: 0

Views: 1001

Answers (1)

Vijay Kumar
Vijay Kumar

Reputation: 69

Because boolean value is converted to text in URL, so you need to manipulate it as text or try parsing 0,1 rather than true, false.

Conceptually anything not blank or other than 0 is true.

Upvotes: 0

Related Questions