jquery looping array of arrays on $.ajax request -


i have ajax request polling server every 5 seconds returns json array of data available users shopping carts contents.

the json correctly formed , being returned everytime without problem.

json

[     {         "status": "success",         "responsecode": "00",         "data": [             {                 "partnumber": "part 1",                 "status": "true",                 "quantity": "4",                 "productid": "item-1",                 "name": "product 2",                 "online": "1"             },             {                 "partnumber": "part 2",                 "status": "false",                 "quantity": "0",                 "productid": "item-2",                 "name": "product 2",                 "online": "1"             }         ]     } ] 

jquery function process ajax response

function dopoll(){        $.ajax({            type: "get",            url: "/assets/static-pages/shopping-cart/?action=check-cart",                        datatype : 'json',             success: function(html) {             $.each(html, function(key, value)                  {                     console.log(value.data[key].partnumber);                 }              );              }     });     //   settimeout(dopoll,10000); } 

every time loops, return first item in array, loop array , return resides within "data" array can manipulate ui based on contents, reason cant figure out how data.

any suggestions appreciated

your json array, have access index, case 0.
don't need access using key, because it'll loop thrue each data object, it's stored value.

$.each(html[0].data, function(key, value) {     console.log( value.partnumber ); }); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -