This is my first time using Jquery Ajax.
The context is that, i'm trying to display more than 10000 rows of data on Datatable, what i did previously was just to use my servlet to forward my Arraylist of data to the JSP, then loop through and display the data onto display data.
It was taking too much to load the datatables. So i decided that i want to try to use Jquery Ajax to see if that will help the issue.
I'm currently facing some issues implementing it, can anyone help me?
I'm using GSON to serialize my arraylist.
servlet.java
String json = gson.toJson(listS);
...
request.setAttribute("listS", json);
request.getRequestDispatcher("WEB-INF/index.jsp").forward(request, response);
index.jsp
String list = (String) request.getAttribute("listStartup");
......
<td>Insert 1st Element</td>
<td>Insert 2nd Element</td>
<%
};
......
<script>
$(function () {
<% list = (String) request.getAttribute("listS");%>
$("#sp").DataTable({
"scrollY": 500,
"scrollX": true,
"paging": true,
"lengthChange": false,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": false,
"processing": true,
"serverSide": true,
"ajax" : list
});
});
</script>
My JSONarray is structured like this, this is the output
[
{
"Element1": "Text",
"Element2": "Text",
},
{
"Element1": "Text",
"Element2": "Text",
},
....
]
If anyone would be kind to link me to some useful documentation that i can read through. I can't seem to find anything that is helpful for me now.
I'm not sure how to iterate through my JSONarray to access the objects and display my JSON data. If there are 1000 objects, i will iterate through each object and display their datas in a row.
I also don't know how to make it work with Data tables...
"ajax" : listline is invalid). See e.g. stackoverflow.com/questions/44678192/… for hint.