From 57691e6a7f2687bf220b5f7df2f06309b5f634aa Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sat, 6 Jun 2026 05:30:20 +0530 Subject: [PATCH] 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 --- app/Views/billing/ipd/discharge_create.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Views/billing/ipd/discharge_create.php b/app/Views/billing/ipd/discharge_create.php index f437ce6..1762bc7 100644 --- a/app/Views/billing/ipd/discharge_create.php +++ b/app/Views/billing/ipd/discharge_create.php @@ -2010,6 +2010,9 @@ $allergyStatusNoKnown = in_array($allergyStatusNormalized, ['no known drug aller fetch('', { method: 'POST', + headers: { + 'X-Requested-With': 'XMLHttpRequest' + }, body: formData }).then(function(response) { return response.json();