I am struggling very hard to find the mistake in my code. I send a beacon with some data to a controller route where the data should be saved in the database. When checking the developer console, I can see that I receive an error (400 bad request) as answer to the beacon request, but when checking if the beacon returns true or false, it's true.
Beacon:
var data = new FormData();
data.append('pageid', '{{page::id}}');
data.append('userid', uid);
data.append('language', '{{page::language}}');
navigator.sendBeacon('/time/', data);
Controller:
$user = $this->security->getUser();
// Check if user is authenticated
if($user instanceof FrontendUser && $_SERVER['REQUEST_METHOD'] === 'POST') {
// Query
$sql = '...';
// Execute Query
$result = $this->connection->fetchAssociative($sql);
$objResponse = new Response($sql);
} else {
// Redirect
return new RedirectResponse(\Controller::replaceInsertTags('{{page::language}}') . '/');
}
return $objResponse;
I already commented out the controller code or just gave a simple string as response back but I always receive this 400 error. Does anyone of you know where I should look for the mistake or has a clue?