问题
In WAMP I changed the root directory from C:\wamp\www to C:\wamp\www\public. I have a file named username.html it communicates through Ajax with simple.php. This works fine if simple.php is in C:\wamp\www\public but if I move it to C:\wamp\www\private nothing happens.
NOTE I elected not to use jquery and am doing this with plain 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
回答1:
That is because now, public is your webroot and you are requesting the site from the webserver. The "private" directory is out of the reach of your webserver, because is out of the webroot. You can access it directly from your PHP script (i.e. via fopen(), include, require,... if it is allowed in security settings), but webserver can not serve it directly.
来源:https://stackoverflow.com/questions/14763416/trouble-accessing-file-in-other-directory-using-ajax-am-i-specifying-the-path-w