使用PHP获取Ace编辑器内容

时间:2014-05-03 12:04:02

标签: php web editor

嘿伙计们,我想知道是否有可能在我使用PHP的标签中获取内容。我正在使用Ace编辑器,我有一个保存按钮。我正在尝试使用PHP将内容保存到文件中,有人可以告诉我如何使用PHP获取内容吗?

1 个答案:

答案 0 :(得分:0)

愿你可以通过AJAX保存它, 使用POST方法发送编辑器内容和所需的文件名(以及路径)

例如

function saveCode () {
    $.ajax({
        url: 'handler.php',
        type: 'POST',
        dataType: 'html',
        data: {code: editor.getValue(), filename: './test.php'},
    })
    .done(function(result) {
        console.log("success");
    });
}

然后在handler.php上

<?php

    if(isset($_POST['code']))
    {
        file_put_contents($_POST['filename'], $_POST['code']);
        echo 'success';
    }

?>