jCarousel jQuery ajax loading 1000 records

Posted by user1714862 on Stack Overflow See other posts from Stack Overflow or by user1714862
Published on 2012-10-02T21:36:08Z Indexed on 2012/10/02 21:37 UTC
Read the original article Hit count: 155

Filed under:
|

I'm using jCarousel to present a vertical scolling list of +-1000 names. I am using ajax to load the data 100 records at a time then when all the data has loaded I just let the jCarousel loop in the DOM. I have the ajax and loop all working but would like to make the code work no matter how large the total record count becomes.

1) I'd like to eliminate the 1201 fixed number and use a variable. 2) I currently loop on every record I see (carousel.first) to see if it matches my reload position(s) (albeit the loop is ony 12x it still seems a little "loopy")

Any suggestions on improving this?

        function mycarousel_itemLoadCallback(carousel, state)   {
        //if (carousel.has(carousel.first, carousel.last)) {                                                
        //return;           
        //}             
        var getCount = 100;     // Number of records to grab at a time
        var maxCount = 1201;    // total possible number of records
        var visible = 9;        // the number of records you can see in the window so this creates a pre-load by this number of records         
        for (var i = 1;  i < maxCount; i+=getCount ) { 
            if (carousel.first === 1 || carousel.first === (i-visible)){                
                var getFrom = i;                    
                var getTo = getFrom+(getCount-1);
                //alert('TOP Record ='+carousel.first+'\n Now GET '+getFrom+'-'+getTo);                 
                jQuery.get('#ajaxscript#', {
                        first: getFrom,
                        last: getTo
                    },
                    function(xml) {
                        mycarousel_itemAddCallback(carousel, getFrom, getTo, xml);
                    },
                'xml'
                );                  
            break;
            }
        }
    };

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jcarousel