Sven Tjeerdsma
Sven Tjeerdsma

Reputation: 283

he value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true'

in my application i'm building a frontend website (build on React) and i use PHP as my backend. I keey getting the error:

jquery.js:9600 Failed to load http://localhost:81/: The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

my PHP headers are:

header('Access-Control-Allow-Origin: http://localhost:3000'); 
// header("Access-Control-Allow-Origin: *"); 
header('Content-Type: application/json');
header('Access-Control-Allow-Headers');
header('Access-Contol-Allow-Credentials: true');

my frontend request looks like this:

$.post(
    {
      async: false,

      type: "POST",
      url:'http://localhost:81',
      data: 
      {
        querytype: "dataRequest"
      },
      crossDomain : true,
      xhrFields: {
          withCredentials: true
      },
      complete: this.completed,
      success: this.reqsuccess,
      error: this.reqError
  });

Upvotes: 1

Views: 3604

Answers (1)

Nadir Latif
Nadir Latif

Reputation: 3773

Well you have not specified values for the header "Access-Control-Allow-Headers". The value should be a comma separated list of request headers that are allowed. The header is optional and not required for Cross-Site Origin Requests (CORS). See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers.

Upvotes: 1

Related Questions