Pulley scrolling to the bottom of the page Ajax loading data combined with JSONP realization discussion _ajax related

Source: Internet
Author: User
Tags bind jquery library
Scrolling down to the bottom of the page load data is a lot of waterfall streaming site practice, that to see how to achieve with JSONP, side dishes summary record, the master do not spray.

Of course, this example uses the jquery library, the latter will be made into native JS.
The data in this example is called the sharp jquery Book provided by a section of JSON.

First of all to determine how the page is scrolling to the bottom, that is, Scrolltop+window's height is greater than the document's Height,jquery the following code: $ (Window). scrolltop () +$ (window). Height () >=$ (document). Height ();
Then bind the window to the scroll event. So the entire page demo can do this:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<style type= "Text/css" >
* {margin:0; padding:0;}
body {font-size:12px;}
p{margin:5px;}
. box{padding:10px;}
</style>
<!--introduction of jquery-->
<script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type= "Text/javascript" ></ Script>
<script type= "Text/javascript" >
$ (function () {
$ (window). bind (' scroll ', function () {Show ()});
Function Show ()
{
if ($ (window). scrolltop () +$ (). Height () >=$ (document). Height ())
{
Ajaxread ();
}
}
function Ajaxread ()
{
var html= "";
$.ajax ({
Type: ' Get ',
DataType: ' Jsonp ',
URL: ' http://api.flickr.com/services/feeds/photos_public.gne?tags=car&tagmode=any&format=json& Jsoncallback=? ',
Beforesend:function () {console.log (' Loading ... ')},
Success:function (data) {
$.each (Data.items,function (I,item) {
html+= ' <div class= ' box ' > ';
html+= ' html+= ' <a hreft= ' +item.link+ ' ></a> '
html+= ' <div> ' +item.tags+ ' </div> ';
html+= ' </div> ';
});
$ ("#resText"). Append ($ (HTML));
},
Complete:function () {Console.log (' mission Acomplete. ')}
});
}
})
</script>
<body>
<p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p> <p> GoPull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down </p><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> Pull down &LT;/P&G.T;<p> down </p><p> down pull </p><p> down pull </p><p> down </p><p> pull down </p ><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p ><p> down </p><p> down pull </p><p> down </p><p> pull down </p><p> pull </p ><p> pull down </p><p> down pull </p>
<div id= "ResText" >
</div>
</body>

Pull to the bottom is to implement asynchronous data loading, of course, the actual project will add if there is no data to show how to operate. These judgments will do.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.