netorica Posted January 18, 2020 Report Posted January 18, 2020 Can you lead me to a tutorial how can I make a POST ajax request that is secured like with the form submissions with CSRF. Thank you Quote
Tyson Posted January 20, 2020 Report Posted January 20, 2020 $(this).blestaRequest( 'POST', '/uri/path/to/post/to/', $('#my-form').serialize(), function (data) { // Do something on success }, function (data) { // Do something on error }, { dataType: 'json' } ); Quote
netorica Posted January 21, 2020 Author Report Posted January 21, 2020 I have no <form> as I am working on a very dynamic input on a page. Can I still use your code? Quote
Tyson Posted January 21, 2020 Report Posted January 21, 2020 A CSRF token is generated when the form is created using the Form component. If you're doing everything in JS, you need to fetch the CSRF token, either from another form on the page, or via an AJAX request that returns the CSRF token, and then add it to your form in the proper format. Quote
netorica Posted January 22, 2020 Author Report Posted January 22, 2020 7 hours ago, Tyson said: via an AJAX request that returns the CSRF token, and then add it to your form in the proper format. how can I get the CSRF token via ajax? Quote
Tyson Posted January 22, 2020 Report Posted January 22, 2020 Create an AJAX end-point that uses the Form component to create and return it. Take a look at the Form component class. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.