403 error in AJAX to Controller - 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: 403 error in AJAX to Controller (/showthread.php?tid=74703) |
403 error in AJAX to Controller - anonymous5421 - 10-27-2019 Hello. I am trying to send an string from "View" to the "Controller" with AJAX, but give Error 403. (CodeIgniter 4) RE: 403 error in AJAX to Controller - ciadmin - 10-27-2019 You need to provide a lot more information than just this, before anyone can help you. The only thing someone could point out is that a 403 is "access forbidden", if that helps. RE: 403 error in AJAX to Controller - mintwint - 10-27-2019 check csrf token RE: 403 error in AJAX to Controller - ecampait - 10-27-2019 Hi, as said @mintwint you must have the CSRF enabled. In your code ajax replaces the method POST by GET and if it works it is the CSRF which has the cause. In this case, add the CSRF name and hash in the data string. RE: 403 error in AJAX to Controller - anonymous5421 - 10-27-2019 (10-27-2019, 07:22 AM)mintwint Wrote: check csrf tokenHow should I do this? in the $globals in config/Filters.php, csrf is commented: public $globals = [ 'before' => [ //'honeypot' // 'csrf', ], 'after' => [ 'toolbar', //'honeypot' ], ]; RE: 403 error in AJAX to Controller - anonymous5421 - 10-27-2019 (10-27-2019, 07:12 AM)ciadmin Wrote: You need to provide a lot more information than just this, before anyone can help you.View->textbox.php Code: <div style="text-align:center;"> Controller->Links.php PHP Code: class Links extends Controller RE: 403 error in AJAX to Controller - anonymous5421 - 10-27-2019 (10-27-2019, 07:55 AM)ecampait Wrote: Hi, I enabled CSRF and changed textbox.php View: Code: <div style="text-align:center;"> and this code is my Controller: PHP Code: class Links extends Controller RE: 403 error in AJAX to Controller - InsiteFX - 10-28-2019 Your getting an error because your Ajax base url is wrong. Add to your header on top at the bottom before the closing </head> tag Code: <!-- Pass base_url() and site_url() to JavaScript --> Then in your ajax method add this. Code: // Ajax url: Try that. |