"MVC" Ajax+partialview to implement the floor loading of the Mall home page

Source: Internet
Author: User

There are many examples of using AJAX to implement floor loading, but most of the HTML code is manually stitched, inconvenient to write, and difficult to maintain.

The following is the use of ajax+partialview to achieve

1.html Code

class="floor"  id="floor1">    class ="floor"  id="floor2">    < /div><!--Floor 2 End--

2.js Code

<script type="Text/javascript">varSuccessload =NewArray ();//Loaded Floors//scroll bar scrolling$ (window). Scroll (function () {scrollload ();}); //scroll bar scrolling Eventsfunction Scrollload () {varScrollTop = $ ( This). scrolltop (); //load new content when content is scrolled to the bottom$(". Floor"). Each (function (index, value) {if(ScrollTop + $ (window). Height () >= $ ( This). Offset (). Top && $ ( This). Offset (). Top + $ ( This). Height () >=scrolltop) {                if($.inarray (Index +1, successload) = =-1) {Loadfloor (index+1); Successload.push (Index+1);    }            }        }); }    //Floor Merchandise Bindingfunction Loadfloor (loadindex) {if(Loadindex = =1) {$.ajax ({URL: $ ("#GetProductsUrl"). Val (), type:"POST", DataType:"HTML",//format is HTMLsuccess:function (data) {$ ("#floor1"). HTML (data); }, Error:function (msg) {alert ("Error:"+msg.responsetext);         }            }); }        if(Loadindex = =2) {$.ajax ({URL: $ ("#GetProductsUrl"). Val (), type:"POST", DataType:"HTML",//format is HTMLsuccess:function (data) {$ ("#floor2"). HTML (data); }, Error:function (msg) {alert ("Error:"+msg.responsetext);        }            }); }    }</script>

3. Controller

[HttpPost]  Public  return partialview ("Products");}

4.PartialView page

@{    null;} <p>welcome</p>

"MVC" Ajax+partialview to implement the floor loading of the Mall home page

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.