I’m trying to change a javascript file without having to connect via ftp. Therefore i’m using a textarea, where you fill the code in, submit it, and then the content of the textbox is saved to a file on the server (here called ender.js) .
here’s my html, javascript and php (i’m using jquery)
html:
<form>
<textarea id="result" rows="50" cols="150"></textarea>
<input id="submit_btn" type="submit" value="Submit"/>
</form>
javascript:
$('#submit_btn').click(function() {
//alert("Handler for .click() called.");
$.ajax({
type: 'POST',
url: 'opener.php',
data: {test: $('#result').val()},
success: function() {
$('#result').load('js/ender.js');
alert('Load was performed.');
},
error: function() {
alert('error in: ' + settings.url + ' \n'+'error:\n' + xhr.responseText );
}
});
});
php:
<?php
//echo $_POST['test'];
$fp = fopen('js/ender.js', 'w');
fwrite($fp, $_POST['test']);
fclose($fp);
?>
if the textarea contains a ; (point-comma) the file does not change. Why is that?
*edit *
The mistake was in the javascript file.
data: {test: $('#result').val()},
should have been
data: {'test': $('#result').val()},
however I still have an issue if the textarea contains a point-comma “;”
This is surly because it is cached in your browser. I had similar problems. Try to change the filename with a random name or with a parameter like
js/ender.js?rnd=123123