My json file looks like this
{
"Persons": {
"Name" : "e",
"Name2": "e",
"Id": "4700"
}, [...]
}
How does my code looks like to parse/load this local json file into a html file. I tried everything out but none of them worked.
Here's an example from (http://youmightnotneedjquery.com/)
request = new XMLHttpRequest();
request.open('GET', '/my/url', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400){
// Success!
data = JSON.parse(request.responseText);
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function() {
// There was a connection error of some sort
};
request.send();
Your data
variable will then have accessible members like this:
alert(data.Persons.Name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With