POST请求警告它已成功,但未发送数据

I have a JavaScript code that is supposed to send some data to a php file on the server. The JavaScript code gives an alert that the post was successful, but no data is on the php file. No errors show up in the console. What is the problem here?

Here is the code:

var data = "It works";
var url = "data.php";
var http = new XMLHttpRequest();
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert("It worked");
}
}
http.send(data);

Here is the site for the code: http://mikeyrichards.freeiz.com/run.html

EDIT: A clarification, I only want the data to show up like a text file on the PHP. For some reason, my server cannot open text files, so I have to use PHP

You need to send data in key value format something like this

var data = "lorem=ipsum&name=test";

Try changing to:

var data = 'data=It+works';

Then you can access it in the PHP script as $_POST['data'].

Don't forget to encode the space as + or %20. If you're generating the data dynamically, use encodeURIComponent to encode it properly:

var data = 'data=' + encodeURIComponent(value);