CORS policy Error

When run the app shows an Error

Access to XMLHttpRequest at ‘’ from origin ‘http://localhost:8101’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.


export class AccessProviders{


    constructor(private http:HttpClient

        ) { }


            let headers=new HttpHeaders({

            'Content-Type':'application/json; charset=UTF-8'


            let options= { 

                headers : headers


            return + file , JSON.stringify(body),options)





header('Access-Control-Allow-Orgin: *');
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Origin,Content-Type,Authorization,Accept,X-Requested-With,x-xsrf-token");
header("Content-Type: application/json;charset=utf-8");
include "config.php";
$today=date('Y-m-d H:i:s');

          $checkmail=mysqli_fetch_array(mysqli_query($mysqli,"SELECT email_address FROM register WHERE email_address='$postjson[email_address]'"));

            $result=json_encode(array('success'=>false,'msg'=>'Email Already Registered'));


                $insert = mysqli_query($mysqli,"INSERT INTO register SET 
                your_name ='$postjson[your_name]',
                email_address ='$postjson[email_address]', 
                password ='$password', 
                confirm_pass ='$postjson[confirm_pass]',
                created_at  ='$today'
                    $result=json_encode(array('success'=>true,'msg'=>'Register Successfully'));
                    $result=json_encode(array('success'=>false,'msg'=>'Register error'));

          echo $result;

How to solve…Any one Help…

What i use with Nodejs:

const corsOptions = {
  allowedHeaders: [
  origin: [
    'http://localhost:4200', // Angular
    'http://localhost:8101' // For Second Ionic
  credentials: true,
  preflightContinue: false,
  optionsSuccessStatus: 200

// Cors

P.S. Default is 8100. If you run a second project same time it uses 8101 as in your situation.

i am new one for ionic…where i use this code

It’s not about Ionic. It’s about your backend. I use it in NodeJs so you can not copy paste. You should implement it in your backend ( process_api.php). Set origins that will be allowed.

In fact you have a setting but seems like it’s misspelled:

header(‘Access-Control-Allow-Orgin: *’);
header(“Access-Control-Allow-Origin: *”);

Ok Thankyou i will Check…