I have the following code for external api call in php that works fine however when I do this with jquery it gives CORS policy error .
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: ' . $token,'Accept: application/json'));
curl_setopt($curl, CURLOPT_URL, 'http://api.evalu-8.com/employee/readall');//?active=true
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$result = curl_exec($curl);
curl_close($curl);
However when I do the same in jquery it gives error : "Access to XMLHttpRequest at "" from origin "" has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status"
$.ajax({
url:'http://api.evalu-8.com/employee/readall',
crossDomain:true,
type: 'GET',
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type':'application/json'
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization: Bearer ', 'token');
},
success:function(response){
}
});