使用Ajax访问其他目录中的文件时出现问题,是我指定的路径错误吗


Trouble accessing file in other directory using Ajax, am I specifying the path wrong?

在WAMP中,我将根目录从C:'wamp'www更改为C:'wamp'www'public。我有一个名为username.html的文件,它通过Ajax与simple.php通信。如果simple.phpC:'wamp'www'public中,这很好,但如果我将其移动到C:'wamp'www'private,则不会发生任何事情。

注意:我选择不使用jquery,而是使用纯javascript。

xmlhttp.open("GET", "simple.php?suite="+top,true);//works when simple.php is in same folder
xmlhttp.open("GET", "..'private'simple.php?suite="+top,true);//doesn't work
xmlhttp.open("GET", "../private/simple.php?suite="+top,true);//doesn't work
xmlhttp.open("GET", "..//private//simple.php?suite="+top,true);//doesn't work

这是因为现在,public是您的webroot,您正在从web服务器请求该站点。"private"目录是您的Web服务器无法访问的,因为它在Web根目录之外。您可以直接从PHP脚本访问它(即通过fopen()、include、require,。。。如果在安全设置中允许),但是webserver不能直接为其提供服务。