This commit is contained in:
Thanakorn S
2026-02-24 11:18:04 +07:00
parent 42a38760a3
commit 8625652fe7
5 changed files with 80 additions and 7 deletions
+17 -1
View File
@@ -199,8 +199,21 @@ function ajax_request(options) {
}
options.data = { json: JSON.stringify(payloadJson) };
// IF formData exist, we pass as $_POST [not json]
if (options.formData instanceof FormData) {
// THE BYPASS: If formData exists, move all text data into it
Object.entries(payloadJson).forEach(([key, value]) => {
options.formData.append(key, value);
});
// Override options.data with the full FormData object
options.data = options.formData;
}
}
// --- START MODIFIED $.AJAX BLOCK ---
let isSendingFiles = (options.data instanceof FormData);
if (options.debugMode) {
console.log("REQUEST DATA:", options.data);
}
@@ -219,7 +232,10 @@ function ajax_request(options) {
type: options.type || "POST",
url: options.url,
data: options.data,
dataType: "json"
dataType: "json",
// These two settings are only triggered when sending files
processData: isSendingFiles ? false : true,
contentType: isSendingFiles ? false : "application/x-www-form-urlencoded; charset=UTF-8"
})
.then(function (res) {
+10 -5
View File
@@ -58,14 +58,19 @@ if(!empty($_SESSION["login_company_id"])){
// set up ANSWER
$answer = array("success"=>0, "message"=>"");
if(!isset($_POST['json']))
{
$answer["message"] = "No data receive!";
if (isset($_POST['json'])) {
// Old Method: Data is wrapped in a JSON string
$data = json_decode($_POST['json'], true);
} else if (isset($_POST['otp'])) {
// New Method: Data is sent directly (FormData)
// We check for 'otp' because every request should have one
$data = $_POST;
} else {
// Truly no data received
$answer["message"] = "Request denied: No valid JSON payload or Form Data detected.";
exit(json_encode($answer));
}
$data = json_decode($_POST['json'],true);
// incase logging in
if(!empty($_SESSION["login_company_id"])){