使用jQuery和Ajax請求實現分頁效果

2021-06-04 18:00:10 字數 1605 閱讀 3773

在要求分頁的程式中,我們一般會知道如下幾個資料的引數:

總記錄數count

每一頁要顯示的記錄數:size

當前頁:num

總頁數我們可以通過count和size得到,在js中可以使用math.ceil()

編寫我們的js分頁指令碼page.js

//定義乙個page函式,接收兩個引數,總記錄數和引數列表var page = function(count,params);

this.params = {};//定義乙個引數列表

this.first=function()

this.last=function()

this.show(this.num + 1);

} this.show(this.num - 1);

} this.show=function(num) ;

for(p in this.params)

$.get(this.url,args,function(data));

delete args;

} }this.clearcahce();//清除快取

if(num>0&&num<=this.sumnum())else

} this.clearcahce=function()

this.bindform=function(id)

});$('#'+id+' input:checked').each(function(i,input)

});$('#'+id+' select').each(function(i,s)

});$('#'+id).bind('submit',function(f)$$

$ 當前頁:0/0 頁

首頁上頁下頁

末頁 總共條

呼叫page.js和編寫我們的指令碼語句

我們在orderaction中編寫我們的ajaxdish方法
/**

* ajax 獲取菜譜

*/public string ajaxdish() throws exceptionelse

jsonobject object = new jsonobject();

object.accumulate("resid", resid);

object.accumulate("preid", preid);

object.accumulate("count", pagemodel.getcount());

object.accumulate("data", pagemodel.getdatas());

response.setcontenttype("text/plain");

response.setcharacterencoding("utf-8");

writer.print(object.tostring());

}catch(exception e)finally

return null;

}

jQuery傳送Ajax請求

ajax cache false,async true,type post datatype json xml html success function result ajax cache false,async false,type post datatype json xml html suc...

jQuery傳送Ajax請求

ajax cache false,async true,type post datatype json xml html success function result ajax cache false,async false,type post datatype json xml html suc...

原生JS和JQuery的ajax請求

一 原生js 1 get方法 得到xmlhttprequest 開啟與伺服器的連線 var url xhr.open get url,ture 同步為false,非同步為true 傳送請求,get 請求傳送為空 xhr.send null 接收伺服器的響應 xhr.onreadystatechang...