I have tried so many times to get this working but just cannot seem to make ends meet.
When I first implemented this, it worked perfectly for a few requests and then out of nowhere. It stops working.
Here's my code run from a grease/tamper monkey script:
$.ajax({
url: 'ServerLinkHere',
crossDomain: true,
data: {
artist: artist,
track: title,
link: data.url
},
type: 'POST',
success: function (resp) {
console.log(resp.responseText);
}
});
Here's my server side script (Taken from the user Ganesh in a different thread thanks):
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
After the code, I do my computations: Downloading a file and then returning a link to the file download as the body text.
Currently, it seems like the computations are being ran because the file does appear on the filesystem.
However, when it returns a link, the chrome browser still throws the access-control error. Here's a debug picture (couldnt directly attach, no rep):
However, I also hooked up the proxy to CharlesProxy Debugger and the debugger shows that everything is a-okay. Here's a picture of the response:
Could this be a preflight issue? No OPTIONS
was sent on my part.