I want to pass javascript variables (without form) to php, so php can write them in a textfile on the server-side. For this, I'm using this jQuery line:
$.post( "http://localhost/main.php", data);
Here is the php:
$data = $_POST['data'];
echo $data;
$file = "test.txt"
$handle = fopen($file, 'w');
fwrite($handle, $data);
fclose($handle);
I think the problem could be the 'data' tag, when I try to access the information in php, but I don't know what should I put there since all the examples that I found was associated with html forms.
The other thing tho', which I don't really understand is: I do this whole thing on a button-click, so if I click the button, it posts to the php, but does that actually run the above php code, and writes in the text file or am I missing something?
*btw, I use WAMP for PHP, but I don't think it matters.