How create csrf_token with js?

  csrf, javascript

I create many different forms in a foreach loop but I can’t send anyone because of the csrf_token.

inputToken = _("input", null, newFormModiferReduction)  //create <input> with null content, in newFormModiferReduction
inputToken.setAttribute("name", "_tokenDelRed")
inputToken.setAttribute("type", "hidden")
inputToken.setAttribute("value", "{{ csrf_token() }}")

When I did console.log of the value I get : {{ csrf_token() }}

I tried without quotes, without braces, but it still doesn’t work.
I couldn’t find a solution on the Internet.
I tried with only one token in but it doesn’t work without anny "error", I conclued that one form = one csrf_token
I send these forms with AJAX so if there is another solution it could be find too

Source: Ask Javascript Questions

LEAVE A COMMENT