origin 'http://localhost' has been blocked by CORS policies error in codeigniter only due to the path in config page :- Not duplicate question

Viewed 22280

I am getting an error like:

origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. 

This error occurs only when the design is integrated in codeigniter.

Please note who all added this question as duplicate. my question is not a duplicate question of this . My solution is added as the comment. Since, some geeks who think that, its a duplicate question, and reviewd it like so, I am not able to answer my own question. Once I get the privilage to add so, I will move the comment to answer.

Thankyou

1 Answers

You need to add headers in Your requested page:

  // headers
  header("Access-Control-Allow-Origin: *");
  header("Access-Control-Allow-Methods: POST");
  header("Access-Control-Allow-Headers: Origin, Methods, Content-Type");

EDIT

in codeigniter:

$this->output
        ->set_content_type("Access-Control-Allow-Origin: *")
        ->set_content_type("Access-Control-Allow-Methods: POST")
        ->set_content_type("Access-Control-Allow-Headers: Origin, Methods, Content-Type")
Related