ASP.NET Core 2.0
public IActionResult Processing()
{
DoWork();
return View(); // returning Processing.cshtml
// which contains page with animation
}
private async void DoWork()
{
await DoSomething();
// and here I want to redirect
// from page with animation to
// to an action
}
如何从异步方法重定向到操作? await DoSomething()
处理数据时,动画页面必须始终显示。
答案 0 :(得分:2)
基本上,你不能。
由于您没有等待<?php
$postdata = file_get_contents("php://input");
mysqli_report(MYSQLI_REPORT_ALL);
try
{
$link = new mysqli( 'localhost', 'test_account', 'test_password', 'database');
}
catch(Exception $e)
{
echo 'Error: ' . $e->getMessage();
}
if(isset($_POST['submit'])) {
$klas = $_POST['klasDown'];
$naam = $_POST['naamTxt'];
$query = 'INSERT INTO resultaten (Klas, Naam, Percentages, Antwoorden) VALUES (?, ?, ?, ?)';
if ($stmt = $link->prepare( $query ))
{
$stmt->bind_param('ssss', $klas, $naam, $klas, $klas);
$stmt->execute();
$stmt->close();
echo "Insertion succeed";
} else {
echo "Insertion not succeed";
}
}
?>
方法返回的Task
,因此HTTP事务将在DoWork
完成执行之前结束。
使用JavaScript切换到客户端解决方案:
请参阅此主题的例子:Show loading image while $.ajax is performed。