HowTo
HowTo

Reputation: 69

Loading data from external json file with javascript or jquery

I'm looking into dynamically using data from an external json file into my javascript. I must have misunderstood how to call the file because for the moment I can't even access the data... So theres my html calling the js file. and the js file calls the json using this method :

$(function() {
    function stockTimeline(){
        $.getJSON('json/corse_timeline/corse_timeline.json', function(donnees) {
            $('#wrap').html('<p>' + donnees.timeline.date[4].endDate + '</p><p>' + donnees.timeline.date[9].startDate + '</p><p>' + donnees.timeline.headline + '</p><p>' + donnees.timeline.date[30].headline + '</p><p>');
            console.log("this console.log IS NOT working");
        });
        console.log("this console.log IS working");
    }
    stockTimeline(); 
});

I've taken this method right out of several tutorials I've read. How can I test if my json file is corrupted? Is it because I need to upload it on a server for it to work?

Upvotes: 0

Views: 2886

Answers (1)

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114437

You can verify your JSON file by pasting it into JSON Lint.

Upvotes: 4

Related Questions