2013-07-08 36 views
1

我試圖從Jquery中的Ajax調用中獲取值到正在使用CodeMirror腳本的Textarea的value屬性。 我已經嘗試了將textarea的.html()和.val()屬性設置爲我的Ajax調用數據參數的經典方法。從Jquery Ajax調用CodeMirror textarea的值設置

這裏是我的代碼:

<!--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() 
     } 
    }); 
}) 

我跑出來的想法!

+0

嘗試使用editor.setValue() – aljordan82

+0

謝謝aljordan82,它現在是OK! –

回答