jquery - ajax request gets images from server 20 at a time, how to stop sending request when there no images left? -
i jave function ajaxrequest retrieves images server (c# action method) how can stop sending request when there no images left?
i thought sending count of images in html code , if count 0 stop sending correct ? have parse someway comments html. there better way this?
the ajaxrequest function executes every 2 seconds timeout.
code:
ajaxfunction = function() { $.ajax({ beforesend: function() { cleartimeout(loadfromservertimeout); // clear timeout until request ends. }, type: 'get', url: '@url.action("getdata", "greekfurs")', data: { skip: value }, success: function(data) { console.log(data); // data html server loadfromservertimeout = settimeout(ajaxfunction, 3000); // start timer again. }, }); }
ajax view server:
@{ layout = null; var photos = (list<shoppinggalleryphoto>) viewdata["data"]; } <!--count:@photos.count--> @foreach (var photo in photos) { <li><a></a></li> //image links }
you can check number of li
elements returned. if there 20 (ie. limit), need send request. try this:
success: function(data) { console.log(data); if ($(data).filter('li').length == 20) { loadfromservertimeout = settimeout(ajaxfunction, 3000); // start timer again. } },
Comments
Post a Comment