我试图从Jquery中的Ajax调用中获取值到正在使用CodeMirror脚本的Textarea的value属性。 我已经尝试了将textarea的.html()和.val()属性设置为我的Ajax调用数据参数的经典方法。从Jquery Ajax调用CodeMirror textarea的值设置
这里是我的代码:
var editor = CodeMirror.fromTextArea(document.getElementById('code'),{
mode: 'shell',
lineNumbers: true,
theme: 'blackboard'
});
$(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()
}
});
})
我跑出来的想法!
+0
尝试使用editor.setValue() –
+0
谢谢aljordan82,它现在是OK! –