Ajax + jtemplate dynamic paging, ajaxjtemplate

Source: Internet
Author: User

Ajax + jtemplate dynamic paging, ajaxjtemplate

My Space www. cumt. top

The main idea is to copy textarea as a template. ajax loads json data, adds a template, binds data, and updates and loads more events.

// Load more

Function fnLoad (data ){
ListData.Ajax.data.tar get_page = parseInt (data. currentPage) + 1;
Function addmore (){
ListData. Ajax. load ();
}
// Dynamically load more tags
If (data. totalNums = 0 ){
Upload (uploadobj?#.addclass({font-disable{}.html ("no data input !"). Unbind ("click ");
}
If (data. hasNext ){
((“Loadobj”).html ("load more ");
If (data. currentPage = 1 ){
$ ("# LoadOBj"). bind ("click", addmore );
}
} Else {
Upload (uploadobj?#.addclass({font-disable{}.html ("already at 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-wrapp'
})
);
$ ('#' + $ NextListObj). append (nextHtml );
ListPage ++;

Var $ firstH3 = $ ("# listObj. view-box: first h3 ″);
$ FirstH3.next (). show ();
$ FirstH3.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 undefined callback function !");
}
},
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 ();
};

Please specify www. cumt. top for Reference

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.