![]() |
If you're debugging that, I would strip it down and simplify further, you probably don't need the form action on the form-class either if you're firing it off from ajax.
Also your ajax could be greatly simplified, also there's alpinejs ![]()
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
(06-06-2022, 04:09 AM)ignitedcms Wrote: If you're debugging that, I would strip it down and simplify further, you probably don't need the form action on the form-class either if you're firing it off from ajax. thanks, will have a look at alpinjs but would like to try to solve this bug first. Seems the ajax I have is a bare minimum. The ajax request does make it to the controller and to the specific method. It just fails a simple validation rule. On the other hand, I can see the data been summitted via the network tab in chrome and I assume that is correct. Strange thing is that I cannot access the date with getVar or getPost. The method recognizes that the request is a POST, too.
Try sending primitive data a=b with CSRF protection disabled (without passing tokens in the request body).
Use the Developer Tools in your Web Browser F-12 key.
This may also help. Makitweb - How to Send AJAX request with CSRF token in CodeIgniter 4 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thanks and am often using the developer tools to console out debugging info. I have now turned of csfr per below. The controller and method sit under Admin. I have removed the references to csfr and confirm it is working.
PHP Code: public $globals = [ When I submit now, I get [] in the console for " console.log(data);" and under the network tab I get; headers ok 200 request url; https://development.example.com/admin/tasks/create payload; [object Object] preview: [] So I guess I am not sending the form data, right? This is again my js; Code: $(function() {
Just saw this on StackOverflow.
How to send FormData objects with Ajax-requests in jQuery What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Really cannot figure this out but getting somewhat closer. I have rewritten a lot of my code. This is where I am at.
This my controller: Code: public function task_create(){ This is my javascript; Code: $(function() { When I submit the form without the description, I should see an error in the <span> area. I do not. I do see this in the network tab of chrome Code: {success: 0, msg: {description: "The description field is required."}} Above is as expected. When I submit the form with a description, for example "homework", I get an alert say, "development.example.com says: Task Created. Unfortunately, it is not. Under payload in the network tab, I can see; form data, description, homework and status 200 and then after I close the alter, I can see the response as {"success":1,"msg":"Task created"}. In my ci log files, I cannot see that the method is catching the vars as the log file say; ERROR - 2022-06-10 04:47:06 --> id is ERROR - 2022-06-10 04:47:06 --> description is I watch expecting the vars to be written into the log.
I got this working. Thank you all for your help and suggestions.
The controller; PHP Code: public function task_create(){ The javascript for task_create.js. In the headers I do <script> let ajaxUrl = "'.base_url().'";</script> PHP Code: $(function() { And the view. Code: <!-- right side --> If any questions, pleased to help. |
Welcome Guest, Not a member yet? Register Sign In |