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");
        });
    });
});
John Slegers
  • 45,213
  • 22
  • 199
  • 169
Ben
  • 69
  • 1
  • 2
  • 8

2 Answers2

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)

0

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

Hope this helps you.

leguano
  • 171
  • 1
  • 6
  • I don't think this applies. Check the URI: `\\Users\\betzenben\\Dropbox\\Website\\test.json` that looks like a folder – Jared Hooper Jan 18 '16 at 16:32