Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you call a JavaScript (AJAX) function when the user reaches the end of a page to load new content?

On twitter (new twitter) and facebook they now have the the ability to load new tweets and posts when you hit the bottom of the page..

Is there a JavaScript / jQuery event that you can call / add to a div so when the browser hits the bottom it does some ajax call to get the new data?

Thanks

Daniel

like image 937
Daniel Upton Avatar asked Oct 05 '10 11:10

Daniel Upton


People also ask

Which Ajax property's associated JavaScript function is invoked after the page is updated?

It uses readyState property of XMLHTTPRequest; readyState is simply an integer value which describes the status of HTTP request, whenever onreadystatechange function is called when readyState property changes.

Can we call function in Ajax?

A JSON object containing numeric HTTP codes and functions to be called when the response has the corresponding code. A callback function to be executed when Ajax request succeeds. A number value in milliseconds for the request timeout. A type of http request e.g. POST, PUT and GET.

What does an Ajax call return?

The $.ajax() function returns the XMLHttpRequest object that it creates. Normally jQuery handles the creation of this object internally, but a custom function for manufacturing one can be specified using the xhr option.


2 Answers

There's a jQuery plugin for that: Infinite Scroll jQuery Plugin.

And here's the description of the pattern that it implements: The Interaction Design Pattern.

like image 177
Daniel Vassallo Avatar answered Nov 13 '22 00:11

Daniel Vassallo


It's called Infinite Scrolling, and there's a jQuery plugin for it here: http://www.infinite-scroll.com/

like image 40
RichieHindle Avatar answered Nov 13 '22 00:11

RichieHindle