如何在XMLHttpRequest.open中指定硬盘上的文件(“GET”,file.txt,true)?

时间:2021-03-03 07:27:31

I have tried:

我试过了:

[This is not a link](http://localhost/file.txt)

Which did not work. What exactly am I doing wrong?

哪个没用。我究竟做错了什么?

1 个解决方案

#1


0  

You can use the file protocol, but then you'd need to spell out the full path. (To see an example, open a local file from the browser.)

您可以使用文件协议,但是您需要拼出完整路径。 (要查看示例,请从浏览器中打开本地文件。)

Unless you actually have an HTTP server running on your machine, and it is serving the file you want, the URL you're using won't work.

除非您的计算机上实际运行了HTTP服务器,并且它正在提供您想要的文件,否则您使用的URL将无法使用。

#1


0  

You can use the file protocol, but then you'd need to spell out the full path. (To see an example, open a local file from the browser.)

您可以使用文件协议,但是您需要拼出完整路径。 (要查看示例,请从浏览器中打开本地文件。)

Unless you actually have an HTTP server running on your machine, and it is serving the file you want, the URL you're using won't work.

除非您的计算机上实际运行了HTTP服务器,并且它正在提供您想要的文件,否则您使用的URL将无法使用。