所以。当我使用AJAX将php文件与html文件放在同一文件夹中时,我的AJAX请求就可以工作了。类似:
var URL = "question1.php?q1=" + radioValue;
不过,我想将question1.php保存在另一个名为"json"的文件夹中。我试过以下几种:
var URL = "/json/question1.php?q1=" + radioValue;
var URL = "json/question1.php?q1=" + radioValue;
但是AJAX请求由于某种原因跳过了文件夹json之前的路径。类似:
http://localhost/json/question1.php?q1=Ok
而不是
http://localhost/example/json/question1.php?q1=Ok
"example"就是ajax.html所在的位置。我只是想能够在我喜欢的时候将网站切换到服务器,而不改变路径。建议?
考虑到您的json和example文件夹位于目录级别,并且您的ajax是从路径/example执行的,您需要执行:
var URL = "/../json/question1.php?q1=" + radioValue; // /../ would navigate to the parent of json and example.
内部看起来像:
http://localhost/example/../json/question1.php?q1=Ok