I'm trying to save a txt file from javascript by letting ajax call a php script. The callback is successful, however the php is not being executed. Also, running the php script in terminal will create my txt file. So somehow the call is not getting executed? What am I doing wrong?
The javascript:
var data = "test"
$.ajax({
url: 'http://localhost/saver.php',
type: 'POST',
data: { data: data },
success: function(result) {
alert(result);},
error: function(result) {
alert('ERROR');}
});
The php script:
<?php
$data = $_POST['data'];
$fp = fopen('path/hs2.txt', 'w');
fwrite($fp, $data);
fclose($fp);
?>