javascript - length of data in Ajax call -


in application getting json data through ajax call .aspx page

json data format this

 {     "table": [         {             "id": 911,             "source": "vishakhapatnam",             "dest": "goa",             "capacity": 24000,             "h1": 400,             "h1at": 7,             "h1dt": 8,             "h2": 401,             "h2at": 9,             "h2dt": 9.3,             "h3": 402,             "h3at": 12,             "h3dt": 12.3,             "h4": 403,             "h4at": 14.3,             "h4dt": 15,             "h5": 404,             "h5at": 16,             "h5dt": 17,             "h6": 405,             "h6at": 18,             "h6dt": 19,             "h7": 406,             "h7at": 19.3,             "h7dt": 20,             "h8": 407,             "h8at": 21,             "h8dt": 21.3,             "h9": 408,             "h9at": 22,             "h9dt": 22.1,             "h10": 409,             "h10at": 23,             "h10dt": 24         }     ] } 

i checked format in http://jsonlint.com/ valid

from javascript when trying read length of data this

for (var = 1; <= data.table.length; i++) 

data.table.length returning 1 , loop runs once only,i don't know how length of object array inside json data loop can continue till end.

please help

it's because table object contains array 1 element. objects you're looking for, try instead:

for (var = 1; <= data.table[0].length; i++) 

then going inside first element table , you'll number of children inside.

hope helps!

edit

sorry, that's because objects don't have length property. please refer thread on stackoverflow, jquery ajax json response has length undefined , incorrect data

if want loop objects try this,

for (var obj in data.table[0])     console.log(obj) // object 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -