A
A
Andrew2022-02-11 14:18:24
ubuntu
Andrew, 2022-02-11 14:18:24

Laravel. How to embed csrf token in html file?

Hi all.
I implemented it as follows:
Main menu | Task List | Place for task editing form
A......................|Task 1.........|
B.....................|Task 2.........|
When you select item A of the main menu, the Tasks view is loaded in which a list of tasks is formed using the array passed to it and there is an empty div for the form.
When a task is selected in column #3, a form for editing the task via AJAX is displayed (the form is in a separate file, it is read, something is edited through the template engine and embedded in a div using Jquery $("#id")). In order for the completed task to leave the list, I decided to send the form in the usual way using the link /my_site/menu_A, where the list of tasks already without completed ones will be re-formed, etc.
Laravel doesn't accept form without csrf token. In the blade.php views, the issue is simple, but how do I inject the token into a form that is dynamically generated and shown via AJAX ?

Andrei.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ilya, 2016-02-19
@mirspo

0) Ubuna had a diagnostic utility
1) Examine the system logs: /var/log/*.
2) Parse dmesg -l err,warn
3) Observe output of vmstat 1, tail -f /var/log/syslog, /var/log/Xorg.0.log until hang

S
Sergey delphinpro, 2022-02-11
@larush

Insert the token in the meta tag

<meta name="csrf-token" content="{{ csrf_token() }}">

And get it from there with a js script.

A
Andrew, 2022-02-11
@larush

After changing the content of the form, took the token and changed the value of the previously inserted input _token. The error is gone, thanks!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question