从Jquery Ajax调用设置CodeMirror textarea的值

从Jquery Ajax调用设置CodeMirror textarea的值,jquery,ajax,textarea,codemirror,Jquery,Ajax,Textarea,Codemirror,我试图从Jquery中的Ajax调用中获取一个值,该值是使用CodeMirror脚本的Textarea的value属性。 我尝试了将textarea的.html()和.val()属性设置为Ajax调用数据参数的经典方法 这是我的密码: <!--Replaces TextBoxes by the code oriented boxes--> <script type="text/javascript"> var editor = CodeMirror.fromTextA

我试图从Jquery中的Ajax调用中获取一个值,该值是使用CodeMirror脚本的Textarea的value属性。 我尝试了将textarea的.html()和.val()属性设置为Ajax调用数据参数的经典方法

这是我的密码:

<!--Replaces TextBoxes by the code oriented boxes-->
<script type="text/javascript">
  var editor = CodeMirror.fromTextArea(document.getElementById('code'),{
    mode: 'shell',
    lineNumbers: true,
    theme: 'blackboard'
  });
</script>
<!--Jquery Scripts for the Selects and file Edit-->
<script type="text/javascript">
  $(document).ready(function() {
    var directory = $("#directory").val();
    $.ajax({
      type: "POST",
      dataType: "text",
      url: "list_directory.php",
      data: "directory="+directory,
      cache: false,
      success: function(data){
        $("#files").html(data)
      },
      error: function(msg){
        $("#starterror").show()
      }
    });  
  });
  $("#directory").change(function(){
    var directory = $("#directory").val();
    //$("#aux_directory").val(file);
    //alert(file);
    $.ajax({
      type: "POST",
      dataType: "text",
      url: "list_directory.php",
      data: "directory="+directory,
      cache: false,
      success: function(data){
        $("#files").html(data)
      },
      error: function(msg){
        $("#starterror").show()
      }
    });
  })
  $(".edit_item").live('click',function(){
    var directory = $("#directory").val();
    var file = $(this).text();
    $.ajax({
      type: "POST",
      dataType: "text",
      url:"edit_file.php",
      data: { directory: directory, file: file},
      //data: "directory="+directory && "file="+file,
      cache: false,
      success: function(data){
        //alert(data);
        //var file_result = data;
        $("#code2").setValue(data);
      },
      error: function(msg){
        $("#error_loading_file").show()
      }
    });
 })

var editor=CodeMirror.fromTextArea(document.getElementById('code'){
模式:“shell”,
行号:对,
主题:“黑板”
});
$(文档).ready(函数(){
var directory=$(“#directory”).val();
$.ajax({
类型:“POST”,
数据类型:“文本”,
url:“list_directory.php”,
数据:“目录=”+目录,
cache:false,
成功:功能(数据){
$(“#文件”).html(数据)
},
错误:函数(msg){
$(“#starterror”).show()
}
});  
});
$(“#目录”).change(函数(){
var directory=$(“#directory”).val();
//$(“#辅助目录”).val(文件);
//警报(文件);
$.ajax({
类型:“POST”,
数据类型:“文本”,
url:“list_directory.php”,
数据:“目录=”+目录,
cache:false,
成功:功能(数据){
$(“#文件”).html(数据)
},
错误:函数(msg){
$(“#starterror”).show()
}
});
})
$(“.edit_item”).live('click',function(){
var directory=$(“#directory”).val();
var file=$(this.text();
$.ajax({
类型:“POST”,
数据类型:“文本”,
url:“edit_file.php”,
数据:{目录:目录,文件:文件},
//数据:“directory=“+目录&&”file=“+文件,
cache:false,
成功:功能(数据){
//警报(数据);
//var file_result=数据;
$(“#代码2”).setValue(数据);
},
错误:函数(msg){
$(“#加载#文件时出错”).show()
}
});
})
我的点子快用完了

使用
editor.setValue()


尝试使用editor.setValue()谢谢你,现在一切都好了!你有用法的例子吗?