I have a very simple PHP file on an Apache server that have to responds to a Ajax request. I am trying to allow CORS but it doesn't work (Firefox console shows: Reason: CORS header 'Access-Control-Allow-Origin' missing).
I try different solutions from this question but it doesn't work. I an not using any framework, only a index.php file on an Apache server.
This code is the simplest that I found but it doesn't work (index.php):
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 1000");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Cache-Control, Pragma, Authorization, Accept, Accept-Encoding");
header("Access-Control-Allow-Methods: PUT, POST, GET, OPTIONS, DELETE");
echo('CORS activated!!!');
?>
My HTML file:
$.ajax({
type: 'GET',
url: 'http://localhost/index.php',
})
.done(function(data) {
console.log('Do I have CORS?: ' + data);
})
.fail(function() {
alert("Error");
});