berry
berry

Reputation: 49

I try to display json data on alert but cannot display anything

I try to display json data on alert but cannot display anything. I have a json file named json_data.txt and here are my codes;

        $.getJSON('json_data.txt', function(read_data){
            $.each(read_data.movies,function(i,movie){

               alert("Movie Name:"+movie.name+" Actresses:"+movie.actress+" Actors"+movie.actor)

            });
        });

Upvotes: 0

Views: 79

Answers (1)

user254948
user254948

Reputation: 1056

Most likely, based on you accessing a simple txt file, you are running this locally on your computer without a webserver. Some webbrowsers (for example chrome) do not allow javascript to read local files. Hence, in this case jquery would not get access to json_data.txt and be unable to obtain data.

Upvotes: 1

Related Questions