在执行操作之前,我需要检查文件是否存在。为了做到这一点,我是这样做的。
var file = 'file/user/foo.pdf';
$.get(file)
.done(function()
{
// do something
})
.fail(function()
{
alert("The resource is currently unavailable");
})
这工作得很好,但对于绝对路径(PHP DOCUMENT_ROOT),它返回错误的
var file = 'c:/program/ep/www/project/file/user/foo.pdf';
我该如何解决这个问题?感谢
出于安全原因,javaScript无法访问文件系统
你可能想这样做,localhost或127.0.0.1的url或你的ip:
var file = 'http://localhost/project/file/user/foo.pdf';
var file = 'http://127.0.0.1/project/file/user/foo.pdf';