My website has the following structure:
root --> such as localhost or example.com or file:///... etc.
|--css
|--image
: |--folder --> root/image/folder/
|--js
: |--script.js --> root/js/script.js
|--page
: |--index.html --> root/page/index.html
|--index.html --> root/index.html
I use jQuery to write images for root/index.html
and save to root/js/script.js
var db = {
"images" : [
{"image-url": "image/folder/myImage.png"},
{"image-url": "image/folder/myImage.png"},
{"image-url": "image/folder/myImage.png"}
]
}
$.each(db.images, function (key, data) {
var image = data['image-url'];
$('body').append('<image src="' + image + '" />');
}
It works correctly. My images are displaying. I'll try to create index.html
in root/page
and use ../js/script.js
on this page.
But it's seem not display any image. On browser show blank box of image. I'll try to look at F12 and found image-url
return this value.
GET root/page/image/folder/myImage.png net::ERR_FILE_NOT_FOUND
But I want to reference my image at root/image/folder/myImage.png
. I don't know how to write the script for reference image url for to write image and show on any page that use same script. Can't someone to fix this problem.
Thank in advance and sorry for my skill.