This is my first SO question because I honestly cannot find out the reason for this problem and it's driving me nuts because I can't do testing if I can't reconnect after the 1st failed attempt!
I have a HTML running on my local computer (localhost):
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://hostedDomain.com/myBackendScript.php', true);
xhr.onload = function (e) {
console.log(this.responseText);
};
xhr.send();
On the hosted server (I have no access to php.ini
, .htaccess
, .httpd.conf
etc), myBackendScript.php
is simply:
<?php
header("Access-Control-Allow-Origin: *"); //Note: I am not asking about how to configure Access-Control-Allow-Origin
echo "Server Response";
?>
Steps to recreate the problem:
- Surf to hostedDomain and it returns the index
- Surf to hostedDomain/myBackendScript.php and it returns "Server Response"
- Run the localhost html, which fails with a CORS error ("Access-Control-Allow-Origin not present, etc" "403 Forbidden" seen in the browser Console) [Note: I am not asking about how to configure Access-Control-Allow-Origin]
- Surf to hostedDomain no longer works (connection time-out)
- Switch to another network (change public IP, using same computer) - surf to hostedDomain works again
- Wait a couple of days and I'm able to connect to hostedDomain again.
Note: I am not asking about CORS per se or about how to configure Access-Control-Allow-Origin; I am asking about why I am unable to connect to the hostedDomain after the 1st initial failed attempt at XMLHTTPRequest and potential solutions to stop this temporary "ban".
I have a feeling it's got to do with the server configuration; but I have no idea how to proceed further...