Added javascript code to add a result in the background without refreshing the page

This commit is contained in:
Gregory Ballantine
2024-06-03 13:40:26 -04:00
parent b4bd116367
commit 5919226dec
3 changed files with 38 additions and 14 deletions

View File

@ -24,14 +24,21 @@ class ResultController extends Controller {
$result->save();
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('test.view', [
'test_id' => $result->test_id
]))
->withStatus(302);
if (!isset($params['redirect']) || $params['redirect'])
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('test.view', [
'test_id' => $result->test_id
]))
->withStatus(302);
} else {
$payload = json_encode('Success!');
$response->getBody()->write($payload);
return $response
->withHeader('Content-Type', 'application/json');
}
}
}