简体   繁体   中英

Get the number of returned data in $.post()

I'm using jQuery's $.post() to bring data. IT returns data as

[{"ab":"item1"},{"ab":"item2"}]

My question is, how do I get the number of received data in the return function? I want to use it in a for loop.

$.post('add.php',
    { },
    function(data){ 
       //var tot = how to get the number of data received ?
       for(i = 1; i<tot; i++){
       }
    }
);

Since data is a regular array, you can use length

$.post('add.php',
    { },
    function(data){ 
       var tot = data.length;
       for(i = 1; i<tot; i++){
       }
    }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM