使用 AJAX 读取本地文件 [英] Using AJAX to read local files

查看:38
本文介绍了使用 AJAX 读取本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 AJAX 的新手,只想确认一下:如果我将所有代码都放在桌面上的一个文件夹中,并且我使用 AJAX 在 HTML 的 div 中输出文件内容,是否可以访问本地文件通过 AJAX 还是文件必须在服务器上?

I'm a novice to AJAX and just want to confirm: if I have all my code in a folder on my desktop and I am using AJAX to output file content in a div in HTML, is it possible to access local files through AJAX or file should have to be on server?

我只是第一次测试 AJAX 功能,我遇到了问题,因为它在 .js 文件中显示错误拒绝访问"

I am just testing AJAX functionality for the first time and i am facing problem as its showing error "Access denied " in .js file

推荐答案

出于安全原因,JavaScript 对客户端文件系统的访问受到限制 - 考虑您是否希望(其他人的)JavaScript 读取您的敏感文档.

For security reasons JavaScript's access to the file system on the client is restricted - consider whether you would want (somebody else's) JavaScript to read your sensitive documents.

>

即使在试验时最好使用现实拓扑,从服务器提供服务,而在实际系统中则是从那里提供服务.

Even when experimenting it's best to work with a realistic topology, serve things from the server that would be served from there in the real system.

设置 Apache 等 Web 服务器指向您的开发目录非常容易,因此服务器"只是您伪装的桌面.因此,编辑/测试周期非常快.

It's really easy to set up a web server such as Apache to point to your development directory, so the "server" is just your desktop in disguise. Hence the edit/test cycle is really quick.

这篇关于使用 AJAX 读取本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆