I have a query about jQuery's $.each
method. Below is my ajax which is working quite well:
$.ajax({
url:'js/people-json.js',
type:'post',
dataType:'json',
success:function(data){
$.each(data.names, function(i, data) {
console.log(data);
});
},
error:function(err){
console.log(err);
}
});
This script is working fine and giving me the JSON results which I wanted to get. However this is giving me results but this is a long list of information I have stored in an external JS file with a JSON format that looks like this:
{
"people": [
{
"name": "aaa",
"age": 32,
"email": "aaa@abc.xyz"
},
{
"name": "bbb",
"age": 21,
"email": "bbb@abc.xyz"
},
{
"name": "ccc",
"age": 45,
"email": "ccc@abc.xyz"
},
..............lot of more here around 8000
]
}
Is there way to loop in jQuery either this way:
$.each(data.names<=200, function(i, data) {
console.log(data);
});
or this way:
$.each(data.names, function(i<=200, data) {
console.log(data);
});
or this one:
$.each(data.names, function(i, data<=200) {
console.log(data);
});
Can we loop with 200 results at first load and then with click of a button loop with another 200 and so on.
Note: I would prefer jQuery solution for this.