Search code examples
javascriptfilereaderpageloadcodemirror

CodeMirror - load file on editor on page load


I'd like to load inside the Codemirror editor a local file on page load, I've tried using FilerReader APIs without success. I also tried to use the jquery .load() function but I can only load a file in a generic textarea not in the editor.


Solution

  • On page load could wait for data request to complete before initializing codemirror

    Since jQuery mentioned will use it for example

    $(function(){
        $.get('path/to/codefile',  function(data){
              $('textarea#editorId').val(data);
              // now init codemirror 
        })
    
    })