How do you use ajax to submit form contents to a txt file.
<input id="form" placeholder="fill out this" type="text">
<button>Submit</button>
ajax
<script>
$('button').click(function (){
var food = $('#form').val();
$.ajax({
url:'form.php',
type:'POST',
data: food,
});
});
</script>
form.php
<?php
error_reporting(E_ALL);
$data = $_POST['food'];
$f = fopen('filehere.txt', 'w+');
fwrite($f, $data);
fclose($f);
?>
the txt file keeps coming up blank