jquery - parse this JSON and create a new div for each object -
i json php script, , i'm @ point code. do, each object, insert response div.
for example insert "sentences" div id="sentences" , title div id="title", , prepend, or create new 1 each new response.
any tips on how proceed?
<script type="text/javascript"> $(document).ready(function() { console.log("warming up..."); $.getjson("response.php", function( data ) { console.log("got json"); (var = 0; < data.length; i++) { var obj = data[i]; console.log(obj.title); } }); }); </script>
here json response:
{ "sentences" : [ "the big irony behind scorched-earth republican offensive against president obama’s health-care law expansion of coverage uninsured benefit house districts represented republicans as represented democrats.", "regardless of other provisions consider harmful, posture unavoidably means house republicans seeking “protect” surprisingly large number of constituents right obtain health insurance federal assistance.", "recently released census data show that, on average, share of residents without insurance high in districts represented house republicans in represented democrats.", "slightly more republicans (107) democrats (99) represent districts uninsured percentage above national average.", "massachusetts has lowest percentage of uninsured due state-run health insurance, has been in place since 2006." ], "summaryid" : "w76z7a", "title" : "where uninsured americans benefit obamacare?" }
try $.each() because data
not array, object.
$(document).ready(function () { console.log("warming up..."); $.getjson("response.php", function (data) { console.log("got json"); $.each(data, function (key, obj) { console.log(key, obj) $('<div />', { id: key, text: obj }).appendto('body') }); }); });
Comments
Post a Comment