Javascript, how to read local file?

前端 未结 5 983
长情又很酷
长情又很酷 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 15:01

    Being able to read a local file from your browser would be a major breach of security - I for one do not like the idea of any site I visit being able to run code in my browser that would read files from my hard drive. Typically ajax requests are limited to the domain from which the page originated. (However, you can get around this to some extent using techniques like JSONP.) Most browsers will not let you read local files even if the page originated from your local filesystem.

    The other methods mentioned should allow you to read files from a domain (even if it is localhost), but not from your filesystem directly.

提交回复
热议问题