I'd like to save the current content of a codemirror editor using a php script. I used the following codes in the hope when clicking on a button the current content will be passed to the php script. The scripts below has been edited and worked.
var test = code.getValue();
but this does not reflect the change in the editor.
<script language = "Javascript">
function saveData() {
var test = editor.getValue();
new Ajax.Request('savedata.php', {
method: 'post',
parameters: {
test: test,
}
});
}
</script>
The editor is constructed using: ;
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
extraKeys: {"F11": toggleFullscreenEditing, "Esc": toggleFullscreenEditing},
onBlur: function(){editor.save()}
});
Any comments or suggestions are highly appreciate. Thanks.
Note that the CodeMirror's event api has changed (see CodeMirror doc)
So the above should be something like:
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
lineWrapping: true,
extraKeys: {"F11": toggleFullscreenEditing, "Esc": toggleFullscreenEditing},
});
editor.on("blur": function(){editor.save();});
The last code with editor ... You have to put in a function and call it after changing the text area - maybe with OnBlur=""
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With