Good day everybody!
Examined a lot of questions here with a similar problems but they quite different and nothing works. There is problem with third-party resource that author of question not controlling, in my case I am forcibly send header from server but receive nothing: No 'Access-Control-Allow-Origin' header is present on the requested resource error
I have a problem with CORS requests. Here is my JS (using jQuery):
$.ajax({
type: "POST",
url: "http://domain.com/module/api/storeData.php",
data: 'data='+results,
dataType: "html",
async: false,
crossDomain: true,
success: function(msg){
if(msg=="Ok")
{
$("#resultsPane").append ("Results successfully sent.");
} else {
$("#resultsPane").append (msg);
}
},
error: function (xhr, status, errorT)
{
$("#resultsPane").append ("AJAX error: "+status+": "+errorT);
}
});
Very begining of PHP:
<?php
header ("Access-Control-Allow-Origin", "*");
But result is (in console):
jquery.js:10254 XMLHttpRequest cannot load http://domain.com/module/api/storeData.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.
Response headers:
Connection:Keep-Alive
Content-Length:2
Content-Type:text/html
Date:Thu, 13 Oct 2016 13:19:23 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.7 (Ubuntu)
X-Powered-By:PHP/5.5.9-1ubuntu4.17
AJAX errors in browser:
AJAX error: error: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://domain.com/module/api/storeData.php'.
Does someone know what could going wrong? Thank you in advance!