Javascript, how to read local file?

前端 未结 5 974
长情又很酷
长情又很酷 2020-11-30 14:28

I try to read a local file from server. I have been \"googling\" this topic for a while now, and some say it\'s impossible, others that it can be done. During this search I\

5条回答
  •  失恋的感觉
    2020-11-30 14:40

    With javascript you can only read files that are publicly exposed on your server. It's similar to opening it in your browser...

    I suggest to use jQuery library to do this, ajax request with this are much easier and supported by all major browsers:

    http://api.jquery.com/jQuery.get/

    for example you can make it like this:

    $.get('/content/test.html', function(data) {
      alert(data);
    });
    

提交回复
热议问题