JS pull-down automatic loading

Source: Internet
Author: User

Import Jquery.mousewheel.js

Defining url= Paths

Js

1$(function(){2     /*3 * Sliding loading4      * */5     varpage = 1;6     varend = 0;//1 means all loaded .7     varplist = $ ('. Product-list '));8     functionGetData () {9Notice.text (' Loading ...);Ten $.ajax ({ OneAsync:true, AType: ' Post ', - Url:url, -Data: {' page ':p age, ' bid ': Bid,}, theDataType: ' JSON ', -Success:function(msg) { -                 if(msg.status==1){ -Page=Msg.next; +                     if(msg.end==1){ -End=1; +                     } A                      for(varr=0;r<msg.result.length;r++){ atConsole.log (msg.result[0].title); -Str= ' <li><a class= "back block" title= "' +msg.result[r].title+ '" href= "' +link+msg.result[r].id+ '" style= " Background-image:url (' +rt+msg.result[r].img+ ') "></a></li>"; - plist.append (str); -                     } -                      -                 } inConsole.log (Msg.info);//Debug -             }, toError:function(){ +Console.log (' Network failure! ‘); -             } the         }); *     } $GetData ();//Initialize one page of dataPanax Notoginseng$ (' body '). MouseWheel (function(event) { -         if(end!=1&& (' body '). ScrollTop () > (Plist.offset (). Top+plist.height ()-$ (window). Height ()-200))){ the GetData (); +         } AConsole.log ($ (' body '). scrolltop ()); theConsole.log (Plist.offset (). top+plist.height ()); +     }); -});

Ajax Data (PHP)

 functionajaxlist () {if(!is_post) {            $data[' status '] = 0; $data[' info '] = ' illegal request '; $this->ajaxreturn ($data, ' JSON '); }Else{            $page=intval($_post[' page ']);//Current page number            $bid=intval($_post[' bid ']);//category 0 for all            if($bid){                $where[' Bid ']=$bid; }            $number= 6;//number of requests per request            $count= M (' Product ')->where ($where),Count();//Total Quantity            $pageCount=Ceil($count/$number);//Total Pages                        /*Start Request*/            if($page>$pageCount){                $data[' status '] = 0; $data[' info '] = ' No More new films '; $this->ajaxreturn ($data, ' JSON '); }Else{                $sql= M (' Product '); $result=$sql->where ($where)->order (' Sort desc,id desc ')->limit (($number*($page-1)). ', '.$number),Select (); $data[' status '] = 1; $data[' result '] =$result; $data[' sql '] =$sql-Getlastsql (); if($page==$pageCount){                    $data[' Next '] =$page; $data[' info '] = ' new piece Loaded all '; $data[' End '] = 1; }Else{                    $data[' Next '] =$page+1; $data[' info '] = ' Click to load More '; }                $this->ajaxreturn ($data, ' JSON '); }        }    }

JS pull-down automatic loading

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.