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

こ雲淡風輕ζ 提交于 2019-12-12 02:54:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!