Help me please. The code has an Ajax request that sends the data from the form to the server. The server receives data, the file changes, but echo does not send a response, but the script page opens and echo displays the data there.
Form Code:
<form enctype='multipart/form-data' id='change_form' method='post' action='ajax-for-saving.php'> <textarea id='filetext' name='filetext'>$content</textarea> <input type='hidden' name='filename' value='$pathToFile'> <input id='save_changes' type='submit' value='Сохранить' /> </form> Request Code:
$('#change_form').on('submit', function(e) { e.stopPropagation(); e.preventDefault(); var changeForm = new FormData($('#change_form').get()[0]); $.ajax({ type: $(this).attr('method'), url: $(this).attr('action'), data: changeForm, contentType: false, processData: false, success: function(data) { alert(data); } }); }); Script code:
<?php echo file_put_contents($_POST['filename'], $_POST['filetext']); 
return false;at the end of the JS functionreturn false;It should get the type of this:$('#change_form').on('submit', function(e) { ... return false; });- Manitikylfile_put_contentsreadsThis function returns the number of bytes that were written to the file, or FALSE on failure.So it seems like everything is correct, and the file is recorded. Check the$pathToFilein the folder whereajax-for-saving.phpis located. - Kosta B.