AJAX / Post / delete record not working |
Still having some problems with AJAX crud. For delete, I have the following controller;
PHP Code: public function task_delete(){ It takes in an $id from $_POST data to delete the specified task. I always get returned 'success' '= 0, msg' => "No Task To Delete". Strangely, I get NULL is my log file for var_dump($_POST) The ajax request is as follows; Code: $(document).on('click', '.delete-task', function(event){ The URL is correct as my log is written to. For type, I have tried 'POST' and 'post' For id, this gets passed in the network window, id=103 where 103 is the row I clicked on. The alert returns success = 0 and 'success' '= 0, msg' => "No Task To Delete". I am stumped as to what the problem is. Any pointers appreciated.
Simply add / before call your ajaxUrl. You need to add slash infront of AJAX url you need to call in CI4
Did you try :
Code: if($id == ""){
(06-21-2022, 11:34 AM)maulahaz Wrote: Did you try : So the problem is I cannot get see any $_POST head info and also cannot see $id in headers. It isn't a logic error, I think. I tried about but as $id is blank it is always "No task to delete". (06-21-2022, 06:48 PM)spreaderman Wrote:(06-21-2022, 11:34 AM)maulahaz Wrote: Did you try : In your Ajax call your dataType is 'json'. However the CONTENT_TYPE may not be correct in the header. Try replacing $request->getVar('id') with $request->getJsonVar('id')
You may need to add the header shown below.
Code: $.ajax({ What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(06-22-2022, 06:36 AM)InsiteFX Wrote: You may need to add the header shown below. Thanks for you comment. I tried that actually but no change. Also, according to the ci4 documentation for jquery the headers don't need to be explicit set. I found the documentation here.
See https://www.php.net/manual/en/reserved.v...s.post.php
Quote:An associative array of variables passed to the current script via the HTTP POST method when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request.
Without having looked at all the detail you've pasted, I've had some similar sounding problems with my ajax crud since I've upgraded from 4.1.8 to 4.2.1... perhaps some of the problem has to do with what's mentioned here: https://forum.codeigniter.com/showthread...#pid397607 (?)
|
Welcome Guest, Not a member yet? Register Sign In |