[英]How to dynamically load more data to the jsp page after it's loaded?
我這里有問題。
前置問題
我主要是前端,但試圖解決一個重要問題。 我所有的后端都在 java 上,我知道你可以在頁面加載之前將數據加載到頁面,然后以 html 格式在 <%= data %> 標記之間顯示它。 但是加載我需要的所有數據需要很長時間。
問題
有沒有辦法在頁面加載后動態加載更多數據? 或者讓它在后台工作(一些異步之王等)?
現在頁面加載前的等待時間為 5-10 秒,而且非常長。 此外,當頁面加載時,一切看起來都像凍結了一樣。
更多信息
如果您需要我的代碼示例等,請告訴我。謝謝!
我嘗試研究它,但只發現了一些使用 jQuery 或其他我不太了解的語言/插件的建議。 如果可能的話,我想做一個只適用於 jave、JS、jQuery 的解決方案。
我實際上找到了解決問題的方法,只是想知道它是否可以保存。
我正在使用以下代碼:我將數據加載到的 Jsp 文件:
<c:import url="AllPendingMyDeals.jsp?<%= UserID %>" var="dataPending" />
//creating span to load data into
<span id="AllPendingMyDealsSpan"></span>
文件 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>
以及調用和加載數據的 javascript 函數:
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(){...}
現在我不確定它有多安全,並且仍在用它解決一些問題。 這是一個好方法還是 Ajax 更好?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.