Closed 23d1 closed 5 years ago
Update:
If I simply change the code somewhat to serialize the form (var data = $(this).serialize();)
, and set the post data to data: data
, it works, but that's not a feasible solution in other parts of the site, like updating amounts of products in the cart by clicking a + and so forth.
Also, defining the CSRF token like so var csrf = $('form#cart-form input[name="CRAFT_CSRF_TOKEN"]').val();
and then passing it as 'CRAFT_CSRF_TOKEN' : csrf,
in the data post seems to work as well.
Should I conclude that there is an issue getting the CSRF token using headers: { X-CSRF-Token : '{{ craft.app.request.csrfToken }} }'
through JavaScript/AJAX?
Nothing changed recently that should have had any effect on the X-Csrf-Token
header. Can you verify that your original code works in 3.1.8 but not 3.1.9?
Gonna test some stuff when I have a moment, but it seems like it could be another dependency that's linked, as when I simply updated to the latest craft in my test environment, and then downgraded vendor/craftcms/cms back to 3.1.8 the issue persisted. I've since then solved it by grabbing the token from the twig generated html instead of relying on sending the header. I'd also be open to testing a non-jquery xhr solution, but I'm not too well versed with xhr and javascript in general.
as when I simply updated to the latest craft in my test environment, and then downgraded vendor/craftcms/cms back to 3.1.8 the issue persisted
OK yeah, most likely something else is the culprit then. Will close this issue.
Description
Ajax posts return 400 error ("Unable to verify your data submission.") after updating Craft CMS. I'm not 100% sure when this issue occurred, but I believe it's one of the later Craft CMS updates (after 3.1.8). I restored to Craft CMS 3.1.8, which works as it should.
Here's one of many ajax calls that fails (seems like they all fail)—sorry for the spaghetti code;
Here's the error in the web.log;
Additional info