Give delay after each call for function called on scroll event
I am calling checkscroll() on scroll event, which is making Ajax requests continuously.
I want to Provide some delay between calls to checkscroll(), so that my first Ajax request gets completed before second time checkscroll() gets called and make ajax request.
Here is my code:

    function scroll(){ $(window).bind('scroll',checkScroll);}
            // calling checkScroll()   on scroll
    function refresh(){flag = 1;}
 
    function checkScroll() {


    if (flag==1){ $(window).unbind('scroll');}

    if(nearBottomOfPage() == 0)
    {
       
      currentPage ++;

      xhr = $.ajax(
        {
            url : '/ideabank?page=' + currentPage,
            beforeSend: function() {
                    $('#loading').show()
                },
                complete: function(){
                    $('#loading').hide()
                },
            

            success : function(){ "can I do something here"}
            
        } );
    }

    }
Give delay after each call for function called on scroll event
===

I am calling checkscroll() on scroll event, which is making Ajax requests continuously.
I want to Provide some delay between calls to checkscroll(), so that my first Ajax request gets completed before second time checkscroll() gets called and make ajax request.
Here is my code:

    function scroll(){ $(window).bind('scroll',checkScroll);}
            // calling checkScroll()   on scroll
    function refresh(){flag = 1;}
 
    function checkScroll() {


    if (flag==1){ $(window).unbind('scroll');}

    if(nearBottomOfPage() == 0)
    {
       
      currentPage ++;

      xhr = $.ajax(
        {
            url : '/ideabank?page=' + currentPage,
            beforeSend: function() {
                    $('#loading').show()
                },
                complete: function(){
                    $('#loading').hide()
                },
            

            success : function(){ "can I do something here"}
            
        } );
    }

    }