I am appending data, via Jquery and AJAX from an external JSP to an existing JSP when a user clicks on a link. For example:
1. This page (page1.jsp) has three HTML tables on it that are populated with data via a servlet/database (servlet number 1) when the page loads. (I load records based on rownum >=0 <= 10 for instance)
2. Then the user clicks a link on this page (page1.jsp) which calls another servlet (servlet number 2) that populates another jsp (page2.jsp). (I load records based on rownum >=10 <= 11 for instance)
3. Using Jquery/Ajax I then append the contents of page2.jsp into one of the tables on page1.jsp.
Kind of confusing I know but it works fine. But my problem is this: How do I tell the original page (page1.jsp) when there is no more data to be appended? For example the user clicks the link on page one and never knows that there returning recordset is empty. Ideally I would like to hide the link on page1.jsp that allows them to add more records when the recordset is empty. I can tell on the page2.jsp and servlet number 2 that there are no more records but how do I pass this info back to page1.jsp?
I know this might be a little confusing but I have not been able to figure this one out.
Bear Bibeault wrote:Sounds to me as if you can just test the size of the response text in your jQuery success handler, and if empty, hide the link.
I think he wanted to check in advance if the there are more results to come and hide the link accordingly, so he would need to send the request even without somebody clicking the link.
Maybe it's faster to run a separate request that just gets the result size as opposed to running the full request and getting the complete result if you only need the size.
JDBCSupport - An easy to use, light-weight JDBC framework -
Thanks to everyone for the quick response. I apologize for putting this in the wrong location initially. These replies have all got me pointed in the right direction. I think I will utilize the method in the Jquery success handler as that makes the most sense to me at this time.
Did you get what Sebastian recommended? From what I could understand, a count request first hand sounds better to me, rather than getting the whole thing on client side, I can't say which one's more performance oriented though, personally I'd keep all those things on server bay and have min. data to deal with on client end.
OK, not being a JQuery expert , I'll leave the js code to you, but you could do this:
1.) allow the processing to happen on server end, and server sends out a JSON response.
2.) have a marker in JSON to see if the data if the links to be displayed.
3.) finally display the results (present in JSON array).
Thanks for following up. Basically what I did was check the results on the client end. If they are empty I no longer append data. The problem with the page is it has 6(!) different tables on it with each querying a different database. (yowsa!) The client wants one button to update/paginate all of them. They also then want the tables with no new data available indicate that there are no more new records. I don't think this is possible for multiple tables. I can easily hide the update link with css for each of the queries but trying to do it for all requires too many round trips to the db I think.
So I am going to provide links for updating each of the tables. And when there is no more data hide those particular links.
Thanks again for yours, and everyone else's, assistance!
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop