I'd like to make an ajax call to a php file; eventually this php file will write to a mongodb database. For now, I am debugging and would like to have the php file open and write to a text file. The php file works when I run it from the command line. Similarly, the ajax call returns a 'success' message. However, the ajax call does not result in the writing of a new text file.
From the relevant part of my javascript file:
$.ajax({
type: "POST",
url: "jq.php",
data: {
'myString': "blahblah",
},
success: function(data) {
alert('worked');
},
error: function(){
alert('failed');
}
});
The php file:
<?php
$file=fopen("welcome.txt","w");
$str = "let's hope this works.";
fwrite($file, $str);
fclose($file);
?>
I have also tried wrapping the above content in: if ($_POST['ajax']) {...}.