Reputation: 141
I have following ajax code:
function handleServerResponse() {
alert(xmlhttp.readyState);
if (xmlhttp.readyState == 4) {
alert(xmlhttp.status);
if (xmlhttp.status == 200) {
var jason = eval('(' + xmlhttp.responseText + ')');
for ( var index = 0; index <= jason.length; index++) {
document.getElementById('product-data').innerHTML += jason[index].productNumber
+ jason[index].productType
+ jason[index].funcDesignation + "<br>";
}
}
In my jsp I display the data with the following code:
<td>
<a href="<portlet:renderURL><portlet:param name='pageAction' value='Navigation'/></portlet:renderURL>"> <div><span id="product-data"></span></div>
</a>
</td>
I want to implement pagination in this code. Please guide with the simplest way possible. I have gone through few tag libraries available but don't know how it will fit in my logic.
Upvotes: 0
Views: 1499
Reputation: 1020
The ajax request is what matters most; you won't have to change much if anything in the response. You'll modify the request such that you send a "start" parameter and a "count" parameter whereby "start" is the index your result set will start at and "count" is the number of results (of course, you can modify your server-side code such that you don't even need to include a count). So, your ajax request URI could look something like this:
/myquery.jsp?start=20&count=10
Your server-side code would parse that and build the SQL query accordingly, e.g.:
SELECT * FROM myTable LIMIT 20, 10
You can keep track of your "start" param value and increment it however you wish.
Upvotes: 1