jQuery: read text file from file system

前端 未结 10 2523
再見小時候
再見小時候 2020-11-30 10:09

I am trying to read a text file using jquery, like this:

// LOAD file and split line by line and append divs
$.get(\'myFile.txt\', function(data) {    
    v         


        
10条回答
  •  误落风尘
    2020-11-30 10:55

    A workaround for this I used was to include the data as a js file, that implements a function returning the raw data as a string:

    html:

    
    
    
    
      
      
    
    
    
      

    check out the data!

    script.js:

    // function wrapper, just return the string of data (csv etc)
    function getData () {
        return 'look at this line of data\n\
    oh, look at this line'
    }
    

    See it in action here- http://plnkr.co/edit/EllyY7nsEjhLMIZ4clyv?p=preview The downside is you have to do some preprocessing on the file to support multilines (append each line in the string with '\n\').

提交回复
热议问题