![]() |
I have a problem with ajax and csrf - The action you requested is not allowed. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: I have a problem with ajax and csrf - The action you requested is not allowed. (/showthread.php?tid=79982) |
I have a problem with ajax and csrf - The action you requested is not allowed. - Secux - 08-29-2021 Hello, I have a problem with ajax and csrf. - this is my code: view: Code: <script> controller: PHP Code: public function view() { error: Code: { RE: I have a problem with ajax and csrf - The action you requested is not allowed. - iRedds - 08-29-2021 You are not sending JSON, but a key = value pair You need to convert JS object to JSON Code: data : JSON.stringify({'<?= csrf_token() ?>':'<?= csrf_hash() ?>'}), RE: I have a problem with ajax and csrf - The action you requested is not allowed. - JrengGo - 03-02-2022 Bro.. you can see my pastebin posting. it will help you full to solve your problem about csrf token random ajax jquery and datatable https://pastebin.com/kupzmyx3 and http://pastebin.com/tHhztmwc hapy coding RE: I have a problem with ajax and csrf - The action you requested is not allowed. - pws - 08-10-2022 (08-29-2021, 10:34 PM)iRedds Wrote: You are not sending JSON, but a key = value pairhello, i do this and work but the problem is work on first time only! so when i reclick on button to call ajax function i see agin the error " The action you requested is not allowed." How can fix this without reload the page? RE: I have a problem with ajax and csrf - The action you requested is not allowed. - PHS - 08-10-2022 Hi, I'm going to take advantage of this thread because today I was all day trying to figure out why my form wasn't being submitted, until I discovered that it was the Security.php > $regenerate setting, which was active. I updated my project with the latest version of CI, in the old project $regenerate was disabled. Well, I would like to ask the CI4 experts what is the implication of leaving $regenerate disabled, is there any threat? Second question, usually in my forms I use javascript to present some special effect to the user when submitting the form, usually I use something like: Code: document.getElementById('myForm').addEventListener('submit', function (event) { If the javascript file submits the form via the method e.currentTarget.submit() and csrf regenerate is enabled the form is not submitted, because as for each request the regenerate changes to a new token. In this case, how could I submit the form, using the same method with javascript and with csrf regenerate enabled? Thanks! RE: I have a problem with ajax and csrf - The action you requested is not allowed. - InsiteFX - 08-11-2022 CodeIgniter 4 CSRF Token with Ajax Request RE: I have a problem with ajax and csrf - The action you requested is not allowed. - datamweb - 08-11-2022 How to Send AJAX request with CSRF token https://t.co/JZT1n2nw23 |