Loading a local JSON file with JavaScript and jQuery
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to load the contents of a JSON file in a JS file and write it to my main HTML file, but am unsure how to approach it.
What I've done so far is as follows:
index.html:
<p>
Name: <span id="dogName1"></span><br>
Breed: <span id="dogBreed1"></span><br>
Age: <span id="dogAge1"></span><br>
Image: <span id="dogImage1"></span><br>
</p>
package.json:
{
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
main.js:
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
);
All I've been able to understand so far is that the code I have in my JS file is the method in which I load the JSON file, but I'm unsure how to proceed
javascript jquery html json
add a comment |
I'm trying to load the contents of a JSON file in a JS file and write it to my main HTML file, but am unsure how to approach it.
What I've done so far is as follows:
index.html:
<p>
Name: <span id="dogName1"></span><br>
Breed: <span id="dogBreed1"></span><br>
Age: <span id="dogAge1"></span><br>
Image: <span id="dogImage1"></span><br>
</p>
package.json:
{
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
main.js:
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
);
All I've been able to understand so far is that the code I have in my JS file is the method in which I load the JSON file, but I'm unsure how to proceed
javascript jquery html json
Hi @Varehen. Do you get info in the console?
– Katie.Sun
Nov 15 '18 at 15:15
1
It is important to know that you cannot load the file, using directory access. Instead you must load it as URL address. Open YOUR_SITE/data/package.json in URL and see if the data appears first, before proceed on jQuery part. Then modify data/package.json to have leading slash eg: /data/package.json
– fwyh
Nov 15 '18 at 15:18
@fwyh that is correct for Chrome but not Firefox
– Katie.Sun
Nov 15 '18 at 15:22
1
@Katie.Sun i did, it came up as "JSON Data received, name is Pets"
– Varehen
Nov 15 '18 at 15:26
Well, in getJSON function you can iterate json.Dogs as @Dhaval Pankhaniya has shown, but instead to console you can use your jQuery with $('#dogName1').html(jsonDogs[i].Name);
– fwyh
Nov 15 '18 at 15:31
add a comment |
I'm trying to load the contents of a JSON file in a JS file and write it to my main HTML file, but am unsure how to approach it.
What I've done so far is as follows:
index.html:
<p>
Name: <span id="dogName1"></span><br>
Breed: <span id="dogBreed1"></span><br>
Age: <span id="dogAge1"></span><br>
Image: <span id="dogImage1"></span><br>
</p>
package.json:
{
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
main.js:
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
);
All I've been able to understand so far is that the code I have in my JS file is the method in which I load the JSON file, but I'm unsure how to proceed
javascript jquery html json
I'm trying to load the contents of a JSON file in a JS file and write it to my main HTML file, but am unsure how to approach it.
What I've done so far is as follows:
index.html:
<p>
Name: <span id="dogName1"></span><br>
Breed: <span id="dogBreed1"></span><br>
Age: <span id="dogAge1"></span><br>
Image: <span id="dogImage1"></span><br>
</p>
package.json:
{
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
main.js:
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
);
All I've been able to understand so far is that the code I have in my JS file is the method in which I load the JSON file, but I'm unsure how to proceed
javascript jquery html json
javascript jquery html json
edited Nov 15 '18 at 16:09
executable
1,98121024
1,98121024
asked Nov 15 '18 at 15:08
VarehenVarehen
81
81
Hi @Varehen. Do you get info in the console?
– Katie.Sun
Nov 15 '18 at 15:15
1
It is important to know that you cannot load the file, using directory access. Instead you must load it as URL address. Open YOUR_SITE/data/package.json in URL and see if the data appears first, before proceed on jQuery part. Then modify data/package.json to have leading slash eg: /data/package.json
– fwyh
Nov 15 '18 at 15:18
@fwyh that is correct for Chrome but not Firefox
– Katie.Sun
Nov 15 '18 at 15:22
1
@Katie.Sun i did, it came up as "JSON Data received, name is Pets"
– Varehen
Nov 15 '18 at 15:26
Well, in getJSON function you can iterate json.Dogs as @Dhaval Pankhaniya has shown, but instead to console you can use your jQuery with $('#dogName1').html(jsonDogs[i].Name);
– fwyh
Nov 15 '18 at 15:31
add a comment |
Hi @Varehen. Do you get info in the console?
– Katie.Sun
Nov 15 '18 at 15:15
1
It is important to know that you cannot load the file, using directory access. Instead you must load it as URL address. Open YOUR_SITE/data/package.json in URL and see if the data appears first, before proceed on jQuery part. Then modify data/package.json to have leading slash eg: /data/package.json
– fwyh
Nov 15 '18 at 15:18
@fwyh that is correct for Chrome but not Firefox
– Katie.Sun
Nov 15 '18 at 15:22
1
@Katie.Sun i did, it came up as "JSON Data received, name is Pets"
– Varehen
Nov 15 '18 at 15:26
Well, in getJSON function you can iterate json.Dogs as @Dhaval Pankhaniya has shown, but instead to console you can use your jQuery with $('#dogName1').html(jsonDogs[i].Name);
– fwyh
Nov 15 '18 at 15:31
Hi @Varehen. Do you get info in the console?
– Katie.Sun
Nov 15 '18 at 15:15
Hi @Varehen. Do you get info in the console?
– Katie.Sun
Nov 15 '18 at 15:15
1
1
It is important to know that you cannot load the file, using directory access. Instead you must load it as URL address. Open YOUR_SITE/data/package.json in URL and see if the data appears first, before proceed on jQuery part. Then modify data/package.json to have leading slash eg: /data/package.json
– fwyh
Nov 15 '18 at 15:18
It is important to know that you cannot load the file, using directory access. Instead you must load it as URL address. Open YOUR_SITE/data/package.json in URL and see if the data appears first, before proceed on jQuery part. Then modify data/package.json to have leading slash eg: /data/package.json
– fwyh
Nov 15 '18 at 15:18
@fwyh that is correct for Chrome but not Firefox
– Katie.Sun
Nov 15 '18 at 15:22
@fwyh that is correct for Chrome but not Firefox
– Katie.Sun
Nov 15 '18 at 15:22
1
1
@Katie.Sun i did, it came up as "JSON Data received, name is Pets"
– Varehen
Nov 15 '18 at 15:26
@Katie.Sun i did, it came up as "JSON Data received, name is Pets"
– Varehen
Nov 15 '18 at 15:26
Well, in getJSON function you can iterate json.Dogs as @Dhaval Pankhaniya has shown, but instead to console you can use your jQuery with $('#dogName1').html(jsonDogs[i].Name);
– fwyh
Nov 15 '18 at 15:31
Well, in getJSON function you can iterate json.Dogs as @Dhaval Pankhaniya has shown, but instead to console you can use your jQuery with $('#dogName1').html(jsonDogs[i].Name);
– fwyh
Nov 15 '18 at 15:31
add a comment |
2 Answers
2
active
oldest
votes
I think what you're looking for is the jQuery append()
method. You use it like this:
$(document).ready(function ()
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
for(let i in json.Dogs)
var dog = json.Dogs[i];
$("#dogTable").append(getDogMarkup(dog));
);
);
function getDogMarkup(dog)
return 'Name: <span class="dogName">' + dog.Name + '</span><br>' +
'Breed: <span class="dogBreed">' + dog.Breed + '</span><br>'+
'Age: <span id="dogAge1">' + dog.Age + '</span><br>'+
'Image: <span id="dogImage1">//image html here</span><br><br>';
What you'll need to do is make something of an anchor point in your HTML that you can fill with the data you want, like so: <div id="dogTable"></div>
Thank you, that helped a lot! i should be able to sort it out from here! :D
– Varehen
Nov 15 '18 at 15:55
@Varehen glad to hear it! If my answer works for you please accept it :)
– Katie.Sun
Nov 15 '18 at 16:04
add a comment |
you can simply iterate json data like below
var jsonData =
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
for(var i=0;i<jsonData.Dogs.length;i++)
console.log("Name : "+ jsonData.Dogs[i].Name)
console.log("Age : "+ jsonData.Dogs[i].Age)
console.log("Bread : "+ jsonData.Dogs[i].Bread)
console.log("------------------------------------")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
He is trying to write to the HTML, not the console.
– Katie.Sun
Nov 15 '18 at 15:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322395%2floading-a-local-json-file-with-javascript-and-jquery%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think what you're looking for is the jQuery append()
method. You use it like this:
$(document).ready(function ()
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
for(let i in json.Dogs)
var dog = json.Dogs[i];
$("#dogTable").append(getDogMarkup(dog));
);
);
function getDogMarkup(dog)
return 'Name: <span class="dogName">' + dog.Name + '</span><br>' +
'Breed: <span class="dogBreed">' + dog.Breed + '</span><br>'+
'Age: <span id="dogAge1">' + dog.Age + '</span><br>'+
'Image: <span id="dogImage1">//image html here</span><br><br>';
What you'll need to do is make something of an anchor point in your HTML that you can fill with the data you want, like so: <div id="dogTable"></div>
Thank you, that helped a lot! i should be able to sort it out from here! :D
– Varehen
Nov 15 '18 at 15:55
@Varehen glad to hear it! If my answer works for you please accept it :)
– Katie.Sun
Nov 15 '18 at 16:04
add a comment |
I think what you're looking for is the jQuery append()
method. You use it like this:
$(document).ready(function ()
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
for(let i in json.Dogs)
var dog = json.Dogs[i];
$("#dogTable").append(getDogMarkup(dog));
);
);
function getDogMarkup(dog)
return 'Name: <span class="dogName">' + dog.Name + '</span><br>' +
'Breed: <span class="dogBreed">' + dog.Breed + '</span><br>'+
'Age: <span id="dogAge1">' + dog.Age + '</span><br>'+
'Image: <span id="dogImage1">//image html here</span><br><br>';
What you'll need to do is make something of an anchor point in your HTML that you can fill with the data you want, like so: <div id="dogTable"></div>
Thank you, that helped a lot! i should be able to sort it out from here! :D
– Varehen
Nov 15 '18 at 15:55
@Varehen glad to hear it! If my answer works for you please accept it :)
– Katie.Sun
Nov 15 '18 at 16:04
add a comment |
I think what you're looking for is the jQuery append()
method. You use it like this:
$(document).ready(function ()
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
for(let i in json.Dogs)
var dog = json.Dogs[i];
$("#dogTable").append(getDogMarkup(dog));
);
);
function getDogMarkup(dog)
return 'Name: <span class="dogName">' + dog.Name + '</span><br>' +
'Breed: <span class="dogBreed">' + dog.Breed + '</span><br>'+
'Age: <span id="dogAge1">' + dog.Age + '</span><br>'+
'Image: <span id="dogImage1">//image html here</span><br><br>';
What you'll need to do is make something of an anchor point in your HTML that you can fill with the data you want, like so: <div id="dogTable"></div>
I think what you're looking for is the jQuery append()
method. You use it like this:
$(document).ready(function ()
$.getJSON( "data/package.json", function( json )
console.log( "JSON Data received, name is " + json.name);
for(let i in json.Dogs)
var dog = json.Dogs[i];
$("#dogTable").append(getDogMarkup(dog));
);
);
function getDogMarkup(dog)
return 'Name: <span class="dogName">' + dog.Name + '</span><br>' +
'Breed: <span class="dogBreed">' + dog.Breed + '</span><br>'+
'Age: <span id="dogAge1">' + dog.Age + '</span><br>'+
'Image: <span id="dogImage1">//image html here</span><br><br>';
What you'll need to do is make something of an anchor point in your HTML that you can fill with the data you want, like so: <div id="dogTable"></div>
edited Nov 15 '18 at 15:38
answered Nov 15 '18 at 15:30
Katie.SunKatie.Sun
587114
587114
Thank you, that helped a lot! i should be able to sort it out from here! :D
– Varehen
Nov 15 '18 at 15:55
@Varehen glad to hear it! If my answer works for you please accept it :)
– Katie.Sun
Nov 15 '18 at 16:04
add a comment |
Thank you, that helped a lot! i should be able to sort it out from here! :D
– Varehen
Nov 15 '18 at 15:55
@Varehen glad to hear it! If my answer works for you please accept it :)
– Katie.Sun
Nov 15 '18 at 16:04
Thank you, that helped a lot! i should be able to sort it out from here! :D
– Varehen
Nov 15 '18 at 15:55
Thank you, that helped a lot! i should be able to sort it out from here! :D
– Varehen
Nov 15 '18 at 15:55
@Varehen glad to hear it! If my answer works for you please accept it :)
– Katie.Sun
Nov 15 '18 at 16:04
@Varehen glad to hear it! If my answer works for you please accept it :)
– Katie.Sun
Nov 15 '18 at 16:04
add a comment |
you can simply iterate json data like below
var jsonData =
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
for(var i=0;i<jsonData.Dogs.length;i++)
console.log("Name : "+ jsonData.Dogs[i].Name)
console.log("Age : "+ jsonData.Dogs[i].Age)
console.log("Bread : "+ jsonData.Dogs[i].Bread)
console.log("------------------------------------")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
He is trying to write to the HTML, not the console.
– Katie.Sun
Nov 15 '18 at 15:18
add a comment |
you can simply iterate json data like below
var jsonData =
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
for(var i=0;i<jsonData.Dogs.length;i++)
console.log("Name : "+ jsonData.Dogs[i].Name)
console.log("Age : "+ jsonData.Dogs[i].Age)
console.log("Bread : "+ jsonData.Dogs[i].Bread)
console.log("------------------------------------")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
He is trying to write to the HTML, not the console.
– Katie.Sun
Nov 15 '18 at 15:18
add a comment |
you can simply iterate json data like below
var jsonData =
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
for(var i=0;i<jsonData.Dogs.length;i++)
console.log("Name : "+ jsonData.Dogs[i].Name)
console.log("Age : "+ jsonData.Dogs[i].Age)
console.log("Bread : "+ jsonData.Dogs[i].Bread)
console.log("------------------------------------")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
you can simply iterate json data like below
var jsonData =
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
for(var i=0;i<jsonData.Dogs.length;i++)
console.log("Name : "+ jsonData.Dogs[i].Name)
console.log("Age : "+ jsonData.Dogs[i].Age)
console.log("Bread : "+ jsonData.Dogs[i].Bread)
console.log("------------------------------------")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
var jsonData =
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
for(var i=0;i<jsonData.Dogs.length;i++)
console.log("Name : "+ jsonData.Dogs[i].Name)
console.log("Age : "+ jsonData.Dogs[i].Age)
console.log("Bread : "+ jsonData.Dogs[i].Bread)
console.log("------------------------------------")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
var jsonData =
"name":"pets",
"Dogs":[
"Name":"Oliveander",
"Breed":"German Shepherd",
"Age":3,
"Image":"images/GermanShepherd.jpg"
,
"Name":"Ripley",
"Breed":"Golden Retriever",
"Age":5,
"Image":"images/GoldenRetriever.jpg"
,
"Name":"Remi",
"Breed":"Siberian Husky",
"Age":2,
"Image":"images/SiberianHusky.jpg"
]
for(var i=0;i<jsonData.Dogs.length;i++)
console.log("Name : "+ jsonData.Dogs[i].Name)
console.log("Age : "+ jsonData.Dogs[i].Age)
console.log("Bread : "+ jsonData.Dogs[i].Bread)
console.log("------------------------------------")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
answered Nov 15 '18 at 15:16
Dhaval PankhaniyaDhaval Pankhaniya
1,6231023
1,6231023
He is trying to write to the HTML, not the console.
– Katie.Sun
Nov 15 '18 at 15:18
add a comment |
He is trying to write to the HTML, not the console.
– Katie.Sun
Nov 15 '18 at 15:18
He is trying to write to the HTML, not the console.
– Katie.Sun
Nov 15 '18 at 15:18
He is trying to write to the HTML, not the console.
– Katie.Sun
Nov 15 '18 at 15:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322395%2floading-a-local-json-file-with-javascript-and-jquery%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hi @Varehen. Do you get info in the console?
– Katie.Sun
Nov 15 '18 at 15:15
1
It is important to know that you cannot load the file, using directory access. Instead you must load it as URL address. Open YOUR_SITE/data/package.json in URL and see if the data appears first, before proceed on jQuery part. Then modify data/package.json to have leading slash eg: /data/package.json
– fwyh
Nov 15 '18 at 15:18
@fwyh that is correct for Chrome but not Firefox
– Katie.Sun
Nov 15 '18 at 15:22
1
@Katie.Sun i did, it came up as "JSON Data received, name is Pets"
– Varehen
Nov 15 '18 at 15:26
Well, in getJSON function you can iterate json.Dogs as @Dhaval Pankhaniya has shown, but instead to console you can use your jQuery with $('#dogName1').html(jsonDogs[i].Name);
– fwyh
Nov 15 '18 at 15:31