2

Please can you people guide me how to make ajax call when scroll down

1
  • SCROLL down triigers a funtion of ajax when reach bottom of page in that footer is reoved it should trigger before footer
    – user887563
    Jan 4, 2012 at 9:50

2 Answers 2

17
var no=1;
$(window).scroll(function () {
    if(no==1)
    {
        if ($(window).height() + $(window).scrollTop() == $(document).height()) {
            no=2;
            $.ajax({
                type: "POST",
                url: "request.php",
                data: datas,
                cache: false,
                success: function(html){

                }
            });
        }
    }
});

This does an ajax call when a user reaches at end of page.

You can specify a height at which it occurs.

5
  • hey raghav can you tell me what does cache does in this
    – user887563
    Dec 31, 2011 at 12:28
  • it tells whether to make a local copy of the data received from ajax call. Dec 31, 2011 at 12:31
  • hey raghav , i want to ask this funtion scroll down call once when window size if once done it shuld not call again again when ever this scroll down on it
    – user887563
    Jan 2, 2012 at 5:40
  • not this one, i mean to ask is ajax call when no data is prest how can i stop the ajax call and another qution is how can i remove the footer from this height which is calculated .
    – user887563
    Jan 4, 2012 at 5:36
  • <div class="head"> </div> <div class="center"> <div class="trigger-scroll">see more</div> </div> <div class="footer"> </div>
    – user887563
    Jan 4, 2012 at 10:01
0

Here is a separate stack overflow question about firing events on scrolling:

jQuery window scroll event does not fire up

And here is jquery's manual that shows how to use ajax:

http://api.jquery.com/jQuery.ajax/

Combine and enjoy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.