編集ウィンドウの内容は、セッションgetValueメソッドで使用できます。たとえば、保存ファイルの標準ACEデモの拡張機能は次のとおりです。
saveFile = function() {
var contents = env.editor.getSession().getValue();
$.post("write.php",
{contents: contents },
function() {
// add error checking
alert('successful save');
}
);
};
demo.jsにある既存の「FakeSave」にsaveFile呼び出しを追加しました。アラートを次のようなコードに置き換えます。
// Fake-Save, works from the editor and the command line.
canon.addCommand({
name: "save",
bindKey: {
win: "Ctrl-S",
mac: "Command-S",
sender: "editor|cli"
},
exec: function() {
saveFile();
}
});
phpファイルは1行だけです:
$r = file_put_contents("foo.txt", $_POST["contents"]) or die("can't open file");