HTML JQuery getJSON return [object Object] -


this question has answer here:

json data structure:

title_day_hourminsec([ {"data":"x", "type":"y"}, {"data":"x", "type":"y"}, {"data":"x", "type":"y"}, {"data":"x", "type":"y"}, {"data":"x", "type":"y"}, {"data":"x", "type":"y"}, ]); 

from call of jquery getjson i'm not able real content of file, got html output:

[object object] [object object] [object object] [object object] [object object] [object object] 

this javascript snippet i've tried json content:

<script type="text/javascript">   $(document).ready(function(){     $.getjson("myremotedata",       function(data){       var items = [];   $.each(data, function(key, val) { items.push('<li id="' + key + '">' + val + '</li>'); });  $('<ul/>', { 'class': 'my-new-list', html: items.join('') }).appendto('body');         });   });   </script> 

what missing?

try modify each loop like:

$.each(data, function (key, val) {     items.push('<li id="' + key + '">' + val.data + ' ' + val.type + '</li>'); }); 

you getting [object object] since in each loop, variable val object. need use javascript dot object notation val.data or val.type values of each object.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -