I have the following simple jquery snippet
$(document).ready(function () {
$.ajax({
url:"myjson.json",
dataType: 'json',
success:function(json){
$.each(json, function() {
alert("test");
});
},
error:function(){
},
});
});
The result can return 1000’s of results – i only want the first 20 for example. How would i best do this?
The callback for
.each()has an argumentindexwhich is the index in the original collection. You break out of the iteration by returning false from the callback.So you would do something like:
As others has commented it is better to do this server side, but maybe you have no access to server side code?