简体   繁体   English

AJAX文件夹路径问题

[英]AJAX folder path issue

So. 所以。 My AJAX request works when I put the php file in the same folder as the html file with the AJAX. 当我将php文件与使用AJAX的html文件放在同一文件夹中时,我的AJAX请求起作用。 Like: 喜欢:

var URL = "question1.php?q1=" + radioValue;

Thing is though that I want to keep question1.php in another folder named "json". 不过,我想将question1.php保留在另一个名为“ json”的文件夹中。 I've tried the following: 我尝试了以下方法:

var URL = "/json/question1.php?q1=" + radioValue;
var URL = "json/question1.php?q1=" + radioValue;

But then the AJAX request skips the path before the folder json for some reason. 但是随后由于某种原因,AJAX请求跳过了文件夹json之前的路径。 Like: 喜欢:

http://localhost/json/question1.php?q1=Ok

..instead of ..代替

http://localhost/example/json/question1.php?q1=Ok

with "example" being where the ajax.html lies. 其中“ example”是ajax.html所在的位置。 I simply wanna be able to switch over the website to a server when I feel like it, without changing that path. 我只是想在需要时将网站切换到服务器,而无需更改路径。 Suggestions? 建议?

Considering your json and example folder are on the level directory level and your ajax is executing from the path /example , you need to do : 考虑到您的jsonexample文件夹位于级别目录级别,并且ajax从/ example路径执行,您需要执行以下操作:

var URL = "/../json/question1.php?q1=" + radioValue;  // /../ would navigate to the parent of json and example.

which would internally look like : 在内部看起来像:

http://localhost/example/../json/question1.php?q1=Ok

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM