javascript - 在 HTML 中将控制器操作的进度显示为文本
问题描述
我正在构建.NET Core应用程序,我想根据控制器操作的进度更改网站上的文本。我在下面写了一个简短的示例,展示了我想要实现的目标。有些东西是用伪代码编写的。
家庭控制器.cs
public class HomeController : Controller
{
private readonly IHomeService _homeService;
public HomeController(IHomeService homeService)
{
_homeService = homeService;
}
public IActionResult Detail(int id)
{
_homeService.ShowInfo(id);
return View(model);
}
家庭服务.cs
public void FirstFunction()
{
// write "Fetching results from database"
...
// write "Results fetched successfully"
}
public void SecondFunction()
{
// write "Parsing results"
...
// write "Results parsed successfully"
}
public string ShowInfo(int id)
{
FirstFunction();
SecondFunction();
return "Success!";
}
函数.js
$(document).ready(function() {
$.ajax({
'url' : 'Home/Detail',
'type' : 'GET',
'data' : {
'id' : 123
},
'success' : function(data) {
// update some html element based on "write" commands in
// FirstFunction() and SecondFunction()
}
});
}
如何使用 FirstFunction 和 SecondFunctions “写入”的字符串更新网页上的 HTML 元素?这些操作很长,我想给用户一些关于现在正在发生的事情的信息。
解决方案
推荐阅读
- processing - 当按下非空格键时,如何确保导弹停留在屏幕上?
- java - 为什么 2 个相似的循环代码在 java 中花费不同的时间
- r - 根据另一列的值更改列的值
- c# - CS0051:可访问性不一致
- amazon-web-services - Fargate 任务在没有 aws configure 的情况下不调用 aws 服务
- c# - 一起使用 Mssql Cascade 和 Setnull
- jdbctemplate - 批量更新到多对多关系
- java - 将带有分隔符“T”的字符串日期转换为 Java 中的 Java.sql 时间戳
- geometry - 如果给定矩形顶点的四个坐标,如何计算矩形的长度和宽度?
- java - Jsoup:从表中获取数据