2

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

  • SCROLL down triigers a funtion of ajax when reach bottom of page in that footer is reoved it should trigger before footer –  Jan 04 '12 at 09:50

2 Answers2

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.

Darbio
  • 11,286
  • 12
  • 60
  • 100
Deept Raghav
  • 1,430
  • 13
  • 14
  • hey raghav can you tell me what does cache does in this –  Dec 31 '11 at 12:28
  • it tells whether to make a local copy of the data received from ajax call. – Deept Raghav Dec 31 '11 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 –  Jan 02 '12 at 05: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 . –  Jan 04 '12 at 05:36
  • see more
    –  Jan 04 '12 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!

Community
  • 1
  • 1
abelito
  • 1,094
  • 1
  • 7
  • 18