我正在构建 .NET Core 应用程序,并且我想根据控制器操作的进度来更改网站上的文本。我在下面写了一个简短的示例,展示了我想要实现的目标。有些东西是用伪代码编写的。
HomeController.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);
}
HomeService.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!";
}
functions.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元素?操作时间很长,我想向用户提供一些有关当前情况的信息。