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