Im trying to send data from my javascript file on GitHub website to my index.php in my /public_html directory on 000webhost. I have enabled CORS in my htaccess file (also in /public_html) in the following way:
php_value display_errors 1
Header set Access-Control-Allow-Origin: URL of GitHub website
Header set Access-Control-Allow-Methods: “GET, POST, DELETE, OPTIONS”
When I send a POST request with data (a=larry) using XMLHttpRequest:
var cli = new XMLHttpRequest();
cli.open(‘POST’, ‘https://palexandrov.000webhostapp.com/index.php?a=larry’);
cli.send();
This is what happens in index.php:
echo $_GET[‘a’] returns larry
echo $POST[‘a’] returns null (‘a’ is undefined index)
If I add ‘a=larry’ into .send() --> cli.send(‘a=larry’) and take it off the end of the URL, both $_GET and $_POST return null
I don’t understand why the server (000webhost) is interpreting the POST request as a GET request. When I look at the request made by my GitHub website in dev on google chrome, it says it is a POST request.
I just want to send some data to index.php.