我只需要使用更改而不是所有文本来提供服务器资源和服务用户。 见Code Mirror: Get Text Around Changes
HTML:
<textarea id="code">script.js</textarea>
JavaScript的:
var id = document.getElementById("code");
var options = {mode:'javascript'};
var editor = CodeMirror.fromTextArea(id, options);
editor.on("change",function(cm,change){
$.ajax({
url:'update.php',
method:'POST',
data:{
save:true,
file:'script.js',
update:change
},
success:function(data){
console.log(data);
}
});
});
PHP:
if(isset($_POST['save']) && $_POST['save'] === true){
if(isset($POST['file']) && file_exists($POST['file'])){
$file = file_get_contents($POST['file']);
if(isset($POST['update']) && !empty($POST['update'])){
$change = @json_decode(@json_encode($_POST['update']));
//here how to use data from $change to update file script.js?
}
}
}
!!