I'm sending a POST request using AJAX like so:
var time = Date.now();
request = $.ajax({
data : 'time=' + time,
url : '/php/save.php',
type : 'POST',
success : function(response) {
alert(response);
}
});
The save.php file looks as follows:
<?php
header('Content-type: text/plain');
header('Access-Control-Allow-Origin: *');
echo $_POST["time"];
?>
And the error message I am getting is:
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
According to questions like this one, the headers I've added should have done the trick. But also, the error itself is a bit confusing because clearly the save.php is in the same domain as the index.html file.
I would be very grateful for any suggestions. Apart from the PHP file configuration I've shown above I've tried many others as suggested by similar questions or answers on Google - no luck so far.
Thanks!