Fix AJAX header for complaint field update to pass CI4 isAJAX() check

BUGFIX: HTTP 400 'Invalid request' when saving editable complaint fields

PROBLEM: After adding the route, the request still returned 400 Bad
Request with 'Invalid request' error. The controller's isAJAX() check
was failing and rejecting the request.

ROOT CAUSE: The fetch() API does not automatically add the
X-Requested-With header that CodeIgniter 4's isAJAX() method checks
for. Unlike jQuery.ajax() which adds this header by default, vanilla
fetch() requires explicit header configuration.

SOLUTION: Added 'X-Requested-With': 'XMLHttpRequest' header to the
fetch request in attachComplaintFieldHandlers() function. This is the
standard header that identifies AJAX requests and is what CI4's
Request::isAJAX() method validates.

Now the editable complaint fields save correctly:
- Type in complaint name/remark
- Press Tab or Enter
- Green border = saved successfully
- Changes persist in database
This commit is contained in:
DevSoftTech Server 2026-06-06 05:30:20 +05:30
parent a1c6ef47b7
commit 57691e6a7f

View File

@ -2010,6 +2010,9 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller
fetch('<?= site_url('Ipd_discharge/update_complaint_field') ?>', {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
body: formData
}).then(function(response) {
return response.json();