I have a simple PHP script that I am attempting a cross-domain CORS request:
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
...
Yet I still get the error:
Request header field
X-Requested-With
is not allowed byAccess-Control-Allow-Headers
Anything I'm missing?
Handling CORS requests properly is a tad more involved. Here is a function that will respond more fully (and properly).
I've simply managed to get dropzone and other plugin to work with this fix (angularjs + php backend)
add this in your upload.php or where you would send your request (for example if you have upload.html and you need to attach the files to upload.php, then copy and paste these 4 lines). Also if you're using CORS plugins/addons in chrome/mozilla be sure to toggle them more than one time,in order for CORS to be enabled
this should work
I got the same error, and fixed it with the following PHP in my back-end script:
Access-Control-Allow-Headers
does not allow*
as accepted value, see the Mozilla Documentation here.Instead of the asterisk, you should send the accepted headers (first
X-Requested-With
as the error says).CORS can become a headache, if we do not correctly understand its functioning. I use them in PHP and they work without problems. reference here