javascript - Unrecognised Json object -
i creating simple app user clicks on button , json object returned database. structure of object shown bellow. however, object not recognized , execution failing. ideas why happening?
response array php passed js
array(2) ( [success] => (bool) true [cnt] => array(2) ( [2014-11-28] => array(2) ( [visits] => (string) 1115 [searches] => null ) [2014-11-29] => array(2) ( [visits] => (string) 493 [searches] => 0 ) ) )
json object
{ "success":true, "cnt":{ "2014-11-28":{ "visits":"1115", "searches":null }, "2014-11-29":{ "visits":"493", "searches":0 } } }
function parsing object
$.post(jobk.ajaxurl, data, function (resp) { if (resp.success) { // append rows $.each(resp.cnt, function (datecol) { $.each(datecol, function (visitscol, searchescol) { // insert row in table @ row index 0 var newrow = tableref.insertrow(tableref.rows.length); }); }); } }, 'json'); });
first of need return valid json string
{"success": true, "cnt": {"2014-11-28": {"visits": "1115", "searches": null}, "2014-11-29": {"visits": "493", "searches": 0}}}
also think not need second loop, 1 =>
// append rows $.each(resp.cnt, function (datecol, date) { var visits = datecol.visits; var searches = datecol.visits; //... here });
Comments
Post a Comment