0

I have a problem here.

Pre-problem

I am frontend mostly but trying to solve one important problem. All my backend is on java and I know you can load data to the page before it loads and then display it in html between the <%= data %> tags. But it takes a very long time to load all the data I need.

Problem

Is there a way to dynamically load more data to the page after it had been loaded? Or make it work on the background (some king of async, etc.)?

Right now waiting time before page loads is 5-10 seconds and it is extremely long. Also, while page loads everything looks like it froze.

More info

Please let me know if you need an example of my code, etc. Thank you!

I tried researching about it but only found some suggestions to use jQuery or other languages/plugins which i did not quite understand. I would like to make a solution which works with only jave, JS, jQuery if possible.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

I actually found a solution to the problem, just wondering if it is save.

I am using the following code: Jsp file which I load data to:

 <c:import url="AllPendingMyDeals.jsp?<%= UserID %>" var="dataPending" />
//creating span to load data into
<span id="AllPendingMyDealsSpan"></span>

file AllPendingMyDeals.jsp:

//loading all libs and classes
<%@ page import="java.sql.*" ..... %>

//Calling the functions from java to load the data
ArrayList<Transaction> AllPendingMyDeals = new ArrayList<Transaction>();
AllPendingMyDeals=myRDS.GetAllPendingBrokerDeals( 1,BrokerID, BrokerID ,"0");
<html>
//creating the template for my data to be displayed (with classes and styles)
 for( Transaction Trans : AllPendingMyDeals){
<div>.....</div>
}
</html>

And the javascript function to call and load data:

function getDataPending(callback){
   $.get('AllPendingMyDeals.jsp', function(response) {
     // Dynamically insert the data into the page
     $('#AllPendingMyDealsSpan').html(response).ready(checkdata());
   });
 }
//function for checking loaded data after loading
 function checkdata(){...}

Now I am unsure how safe it is and am still solving a few issues with it. Is it a good way to do it or Ajax is better?

  • If you read the docs [here](https://api.jquery.com/jquery.get), then you will notice that `$.get` is "a shorthand Ajax function...". – Al-Anazi Dec 16 '22 at 14:58