I want to write data on a file on the server when the user is clicking on a btton. I am using javascript. I tried the method describes here: Saving a text file on server using JavaScript But it doesn't work.
Here my javascript function:
{
if($('radio_dispcor_without').checked)
{
var data = new FormData();
data.append("data" , "the_text_you_want_to_save");
var xhr = new XMLHttpRequest();
xhr.open
(
'post',
'/home/laetitia/Project/WebSite/Website/ChemAlive_Interface/write.php',
true
);
xhr.send(data);
ui.hideDialog('DispCor_DB');
ui.showDialog('without_test');}
if ($('radio_dispcor_first').checked) {
ui.hideDialog('DispCor_DB');
ui.showDialog('first_test');
}
if ($('radio_dispcor_second').checked) {
ui.hideDialog('DispCor_DB');
ui.showDialog('second_test');
}
});
And my php code:
<?php
if(!empty($_POST['data'])){
$data = $_POST['data'];
$file = fopen("text.txt", 'w');//creates new file
fwrite($file, $data);
fclose($file);
}
?>
When clicking on my web page using the debugger console, it tells me: "No element found" pointing to the last line of php file.
Thanks for your help.
Laetitia