0
我想加载一个json文件和一些位于我的根目录之前的其他目录中的图像。我现在正在尝试使用此代码来获取它。它运行良好,但是看起来它不是完美的方式。加载json和位于根目录之外的图像
$.getJSON("http://localhost/folder1/folder2/folder3/content/LB/contents/content.json", function(json){
console.log(json);
}
和图像
<img src="http://localhost/folder1/folder2/folder3/content/LB/contents/locations/locationname/thumbnail.png />
我想的JSON和图像加载到
http://localhost/folder1/folder2/folder3/content/LB/appdrive/html/someHTML.html
http://localhost/folder1/folder2/folder3/content/LB/appdrive/html/js/someJS.js
我只使用HTML,CSS和JavaScript。所以,主要的问题是有没有什么办法JSON和图片的来源更改为类似这样
$.getJSON("folder2/folder3/content/LB/contents/content.json", function(json){
console.log(json);
}
和图像
<img src="../folder2/folder3/content/LB/contents/locations/locationname/thumbnail.png />
还有一两件事要说,FOLDER2是根目录。
是的。您可以将您的网址根植到网站的根目录(例如'/folder2/folder3/.../content.json')。请注意主导斜线。 – ventaur
@ventaur所以我试过这样“$ .getJSON(”/ folder2/folder3/content/LB/contents/content.json“,函数(json){”它没有工作 – Shuvro
@ventaur确定它工作。所以我将它改为“$ .getJSON(”/ folder1/folder2/folder3/content/LB/contents/content.json“,function(json){”),并且它按照预期工作。因为我之前没有使用主要的斜线,所以你的评论帮了很大忙,你可以把它作为答案发布,以便我可以接受它。 – Shuvro