1

I tried to import a json file into my html table. But right now it is not working. I am not sure if the path is right written like that. Or what i am doing wrong. I really hope that someone cane help me.

My JSON file:

{
    "_id": "",
    "_rev": "",
    "geometry": {
        "coordinates": [],
        "type": ""
    },
    "type": "Feature",
    "properties": {
        "editor": "",
        "OS_Version": "",
        "Make_and_M": "",
        "title": "",
        "Name": "",
        "Species_Id": "",
        "timestamp": ""
    }
}

MY HTML Code:

$(function() {
    var people = [];
    $.getJSON('\\Users\\betzenben\\Dropbox\\Website\\test.json', function(json) {
        $.each(json.properties, function(i, f) {
            var tblRow = "<tr>" + "<td>" + f.title + "</td>" + "<td>" + f.Name + "</td>" + "<td>" + f.Species_Id + "</td>" + "<td>" + f.timestamp + "</td>" + "</tr>";
            $(tblRow).appendTo("#userdata tbody");
        });
    });
});
9
  • Do you get an error? What do you mean by "it is not working"? Commented Jan 18, 2016 at 16:09
  • No i get no error it is just not loading the data Commented Jan 18, 2016 at 16:10
  • Unfortunately i have no idea why Commented Jan 18, 2016 at 16:10
  • I think problem is to access local file, it's not allowed Commented Jan 18, 2016 at 16:12
  • 1
    Possible duplicate of Ajax in Jquery does not work from local file Commented Jan 18, 2016 at 16:23

2 Answers 2

1

You need to have the file on your webserver. The file needs to be accessed like http://yourserver/file.json. Also, make sure your webserver supports the .json mime-type, otherwise use .js

You can access local files only if you are in back-end (nodejs for example), otherwise you can't.

Javascript is running on the client-side (in the browser), and you can't access the user filesystem (that will be a security issue)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you i will do that
0

I think, you have to use jsonp to get access on a foreign domain (Same-Origin-Policy).

Hope this helps you.

1 Comment

I don't think this applies. Check the URI: \\Users\\betzenben\\Dropbox\\Website\\test.json that looks like a folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.