10-27-2019, 05:34 AM
(This post was last modified: 10-27-2019, 05:37 AM by anonymous5421.)
Hello. I am trying to send an string from "View" to the "Controller" with AJAX, but give Error 403. (CodeIgniter 4)
403 error in AJAX to Controller
|
10-27-2019, 05:34 AM
(This post was last modified: 10-27-2019, 05:37 AM by anonymous5421.)
Hello. I am trying to send an string from "View" to the "Controller" with AJAX, but give Error 403. (CodeIgniter 4)
10-27-2019, 07:12 AM
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.
10-27-2019, 07:55 AM
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.
10-27-2019, 08:08 AM
(This post was last modified: 10-27-2019, 08:27 AM by anonymous5421.)
(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' ], ];
10-27-2019, 08:20 AM
(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
10-27-2019, 12:21 PM
(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
10-28-2019, 03:37 AM
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|