Access-Control-Allow-Origin header contains the invalid value

San Daniel picture San Daniel · Jan 24, 2018 · Viewed 13.5k times · Source

I have created html page with form submit. On submit i am calling ajax post request. But throws a error

Failed to load http://radius.a3techlabs.com/app/custom/verifyAccessOTP: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains the invalid value ''. Origin 'null' is therefore not allowed access.

$.ajax({
      url: 'http://radius.a3techlabs.com/app/custom/verifyAccessOTP',
      dataType: 'json',
      type:'post',
      headers: {
          "charset":"UTF-8",
          "accept": "application/json",
          "Access-Control-Allow-Origin":"*",
          "Access-Control-Allow-Credentials":"true",
        },
      data:value,
      success: function(data) {
        console.log(data);   
        alert(data.message);
      }.bind(this),
      error: function(xhr, status, err) {}.bind(this)
    });

Answer

San Daniel picture San Daniel · Jan 24, 2018
module.exports.cors = {
  allRoutes: false,
  origin: '*',
  credentials: true,
  methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
  headers: 'content-type'
};

changed

allRoutes:true

module.exports.cors = {
  allRoutes: true,
  origin: '*',
  credentials: true,
  methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
  headers: 'content-type'
};

it works,