Detailed Ajax +jtemplate implement dynamic paging _ajax related

Source: Internet
Author: User
Tags json

Jtemplate is a jquery based template engine plug-in, the function is very powerful, with her you will no longer have to use JS binding data sets and worry about.

Main idea, copy textarea as template, Ajax load JSON data, add templates, bind data, update load more events.

Load more function Fnload (data) {Listdata.ajax.data.target_page=parseint (data.currentpage) +1; function Addmore () {
ListData.Ajax.load (); ///Dynamic Transform load more tags if (data.totalnums = 0) {$ ("#loadOBj"). AddClass ("font-disable"). HTML ("not yet entered data!")
"). Unbind (" click ");} if (Data.hasnext) {$ ("#loadOBj"). HTML ("load more"); if (data.currentpage==1) {$ ("#loadOBj"). Bind ("click", Addmore);} else{$ ("#loadOBj"). AddClass ("font-disable"). HTML ("It's already the bottom!").
"). Unbind (" click ");} Ajaxcallback function callbacklist (data) {var nexthtml = $ (' #listTemplate '). Prop ("outerhtml"); var $listObj = Listpage ==0?
' #listObj ': ' #listObj ' +listpage;
var $nextListObj = ' listobj ' + (listpage+1);
$ ($LISTOBJ). Settemplateelement (' ListTemplate ', null,{filter_data:false});
$ ($LISTOBJ). SetParam ("Imgdomain", Roomimgdomain);
$ ($LISTOBJ). ProcessTemplate (data);
$ ($LISTOBJ). After ($ (' <div></div> ', {ID: $NEXTLISTOBJ, class: ' List-wrap '});
$ (' # ' + $nextListObj). Append (nexthtml);
listpage++;
var $firstH 3 = $ ("#listObj. View-box:first H3″); $firstH3.next (). Show ();
$firstH 3.find ("span"). AddClass ("h3-up"). Removeclass ("H3-down");
Fnload (data);
}
}); //ajax $Ajax. prototype.load = function () {var _this = this; $.ajax ({type: "post", url: _this.url, DataType: ' JSON ', data : _this.data, Success:function (data) {if (_this.callback) {_this.callback (data, _this.id);} else{//console.log ("Ajax does not define callback functions!")
 

");}}, Error:function () {//console.log (" Ajaxerror ");}); Call Function Fnlistajax () {this.
Ajax = new $Ajax (); This.
Ajax.url = ""; This.
Ajax.data = {};
var listdata = new Fnlistajax ();
Fnajax ();
function Fnajax () {ListData.Ajax.url = datadomain+ "/advert/detail.htm"; listData.Ajax.data = {code: ' Index_web '};
ListData.Ajax.callBack = Fncallbackview;
ListData.Ajax.load (); };

The above content for you to share the Ajax +jtemplate implementation dynamic paging, I hope you like.

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.