Cors Error - My Headers
I have attempted to do my homework before asking this question but I cannot see what is missing in my headers. I set the following headers in the javascript: xhr.setRequestHeader('
Solution 1:
This solution seems to work well.
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']) && $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'] == 'POST') {
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With, content-type, access-control-allow-origin, access-control-allow-methods, access-control-allow-headers');
}
exit;
}
header('Content-type: application/json');
header('Access-Control-Allow-Origin: *');
Javascript:
xhttp.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
xhttp.setRequestHeader("Access-Control-Allow-Origin", "*");
xhttp.setRequestHeader("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
xhttp.setRequestHeader("Access-Control-Allow-Headers", "Content-Type");
xhttp.setRequestHeader("Access-Control-Request-Headers", "X-Requested-With, accept, content-type");
Post a Comment for "Cors Error - My Headers"