Hi, I need help to understand how to send data from javascript client to php server.
I want to save some data (a large table) from a web page to a mysql database. I thought the following js and php codes will do that. But it doesn't work so may be I don't understand the concept at all.
The way I understand it is the javascript sends the string "555" to the file 'test.txt' on the server, and the php reads the string from the same file where I can do something with it, eg save to database.
I know the php part works because if I manually create the file test.txt then its content is displayed on the web page. But the javascript code is not updating the file test.txt
javascript
php
I am new to the interaction between javascript and php, so any help would be greatly appreciated.
I am using localhost to test this code
I want to save some data (a large table) from a web page to a mysql database. I thought the following js and php codes will do that. But it doesn't work so may be I don't understand the concept at all.
The way I understand it is the javascript sends the string "555" to the file 'test.txt' on the server, and the php reads the string from the same file where I can do something with it, eg save to database.
I know the php part works because if I manually create the file test.txt then its content is displayed on the web page. But the javascript code is not updating the file test.txt
javascript
Code:
request = new XMLHttpRequest(); request.open("POST", "./test.txt", true); request.setRequestHeader("Content-type", "application/json"); request.send("555");
Code:
$arr = file_get_contents("./test.txt"); var_dump($arr);
I am using localhost to test this code
Comment