POST request to index.php in 000webhost


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();‘POST’, ‘’);

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.


@teodor @Supun any idea?


You should set the third param of open() to true, and the following request header for POST requests

var cli = new XMLHttpRequest();‘POST’, ‘domain/index.php?a=larry’, true);
cli.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

Let us know whether it works.