gpt4 book ai didi

java - 如何从java类的服务层函数中反复调用ajax来显示页码状态?

转载 作者:行者123 更新时间:2023-11-28 09:52:40 25 4
gpt4 key购买 nike

代码:

function importData(pageForm, menuNavigationId, pageId) 
{
showMessageHtml('messageDiv', "Importing data ........");
var url = getURLString(pageForm);
var urlstr = "importTemplate.do?userAction=importData&"
+ url.substring(0, url.length - 1);
ajaxFunction();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
document.getElementById('messageDiv').style.display = 'none';
if (xmlHttp.responseText == "success") {
alert("Data file read and saved successfully.");
} else {
alert("Error while Importing data: " + xmlHttp.responseText);
}
returnToPageUrl("page?pageId=" + pageId
+ "&opType=entry&modType=add&menuNavigationId="
+ menuNavigationId + "&menuPageId=" + pageId);
}
}
}
xmlHttp.open("POST", urlstr, true);
xmlHttp.setRequestHeader("Content-Type", "application/plain");
xmlHttp.send(null);
}

代替“导入数据......”我想传递一个显示页码的字符串......你可以帮助我如何再次调用ajax来获取页面状态。我正在从服务层函数传递这个字符串......需要尽快回复

最佳答案

使用setTimeout(方法,频率);

其中 method 是您的 Ajax 调用,频率是您想要再次调用 ajax 方法的时间段。

根据评论编辑:

假设您的 ajax 调用将调用一个 servlet,然后在您的 servlet 中获取响应的输出流并写入数据:

httpServletResponse.getOutputStream(10);

然后在你的 JavaScript 中你可以像这样访问它:

xmlHttp.responseText 

只需将其显示在您的页面中即可。

关于java - 如何从java类的服务层函数中反复调用ajax来显示页码状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10652103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com