ajax in CI4 - 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: ajax in CI4 (/showthread.php?tid=74789) |
ajax in CI4 - dimonisse - 11-06-2019 Hi to all. I started to deal with CI 4, until that time I had been working with version 3 for several years. There was a problem - I can not transfer data to the controller using Ajax. I suspect that the case is in csrf_token, but did not find a clear explanation in the documentation. In general, here is a view code Code: <input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" id="csrf"/> Code: function inCart(prod_id) { at this stage everything seems to be fine, trying to get my data in the controller PHP Code: if ($this->request->isAJAX()) { in the console I saw just such a picture - at first the data arrives, but then they redirect themselves to themselves and without data. Something is clearly wrong here. after thinking and searching in google, I found a solution that doesn’t quite suit me, but it works - instead of using the POST method I use GET, and then despite the redirects from 301 to 200, the data comes to the controller. RE: ajax in CI4 - dimonisse - 11-13-2019 The problem is solved - at the end of the address of the handler controller in ajax there was a slash. Although, frankly, I did not think that this is such a problem |