I have a piece of javascript:
$.getJSON("something.json",function whatever(data)
Instead of putting something.json
in the same folder as the javascript, I would like to move it one up in the directory structure.
How should I change the code to recognize the new location?
I have a piece of javascript:
$.getJSON("something.json",function whatever(data)
Instead of putting something.json
in the same folder as the javascript, I would like to move it one up in the directory structure.
How should I change the code to recognize the new location?
Share Improve this question asked Nov 6, 2011 at 13:11 David19801David19801 11.4k26 gold badges86 silver badges127 bronze badges 5- 1 This will only work if the target location is still in your web root. If not, the server won't be able to serve the file. – Felix Kling Commented Nov 6, 2011 at 13:13
- My index.html is in my public folder and I am hoping to put the json file one above it for security. Will this not work? – David19801 Commented Nov 6, 2011 at 13:17
- No. If you cannot access the file with an URL, it will not work. And normally you cannot go above the web root. – Felix Kling Commented Nov 6, 2011 at 13:18
- Is there a setting that can make it work? I know with PHP files I can go up there... using ../ – David19801 Commented Nov 6, 2011 at 13:25
- 1 I don't think that is possible, that would be a huge security issue, as everyone could access all files on your server. Yes, PHP can do this, because it is running on the server and can directly access the file system. What you could do is creating a PHP file which reads the JSON file. But what's the point? The client will have access to the JSON data either way. I think your are making things too complicated. Any data which should be transferred between a server and a client is publicly accessible (if it does not require authorization). That's the way it is. – Felix Kling Commented Nov 6, 2011 at 13:29
1 Answer
Reset to default 17The same way as for any other relative URI.
../something.json