javascript - How to iterate json data in jquery + ajax -
but respnce in json, i.e alert(html)
<script> function addcartaction(id){ var datastring='id='+id; $.ajax({ type: "post", url:"<?php echo yii::app()->request->baseurl; ?>/testurl", data: datastring, success: function(html) { alert(html); $("#cart-item").html(html); } }); } </script> { "1": { "itemname": "product1", "id": "1", "item_image": "http://testurl.com/gallerythumb/test.jpg", "price": "4.99", "quantity": 1 }, "2": { "itemname": "product2", "id": "2", "item_image": "http://testurl.com/gallerythumb/test1.jpg", "price": "7.99", "quantity": 12 } }
i have tried alot of different syntax can't seem figure out. can 1 point me in right direction?, can solve one.
once have json string, use parsejson() function, returns object. can access it's properties shown in docs.
also might refer to:
Comments
Post a Comment