jquery - JavaScript variable is "null" -


on line 30 facing issue $.each(data.menu, function (). being told console "data null". can explain whats going on? thanks

function getfoodmenudata () {            var url = 'http://localhost:8888/tom_carp_final_project/chorizios/foodmenu.json';            $.getjson(url, function (data) {                    window.localstorage.setitem('choriziosmenu333', json.stringify(data));            	});        }    function showfoodmenudata () {            var data = json.parse(window.localstorage.getitem('choriziosmenu333'));            var images = "";                $.each(data.menu, function () {            images += '<li class="list-group-item"><img style="width: 100%;" src= "' + this.url + '"></li>';         images += '<li class="list-group-item">' + this.description + '</li>';             });                $('#foodmenu').append(images);          }      showfoodmenudata();

you have call getfoodmenudata(), , inside callback asynchronous $.getjson, call showfoodmenudata().

function getfoodmenudata() {   var url = 'http://localhost:8888/tom_carp_final_project/chorizios/foodmenu.json';   $.getjson(url, function(data) {     window.localstorage.setitem('choriziosmenu333', json.stringify(data));     showfoodmenudata(); // <--- call inside callback   }); }  function showfoodmenudata() {   var data = json.parse(window.localstorage.getitem('choriziosmenu333'));   var images = "";   $.each(data.menu, function() {     images += '<li class="list-group-item"><img style="width: 100%;" src= "' + this.url + '"></li>';     images += '<li class="list-group-item">' + this.description + '</li>';   });   $('#foodmenu').append(images); }  getfoodmenudata(); // <--- call first 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -