PHP-AJAX CORS Fails due to Access-Control-Allow-Origin
I am trying to make an AJAX call (CORS) using the below code: $.ajax({ type: "POST", url: 'http://localhost/MySpace', success: function(result) { console.log(result); }, error: function() { console.log("error"); }, }); I am running the above code from: http://127.0.0.1/Test/index.html The PHP Code written at http://localhost/MySpace is as below: <?php header("Access-Control-Allow-Origin: *"); echo "Hello"; ?> As per my understanding, this should have worked. However I am getting this error: XMLHttpRequest cannot load http://localhost/MySpace. No 'Access-Control-Allow-Origin' header is present