From f6c6a630bc3aec06dc4252949c9ad1c0eb602efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Komj=C3=A1ti=20J=C3=A1nos?= Date: Thu, 8 Dec 2022 23:03:22 +0100 Subject: [PATCH] ajax resolves #392 --- [web]/ajax/ajax.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/[web]/ajax/ajax.js b/[web]/ajax/ajax.js index 543278de1..fcc3bf6c4 100644 --- a/[web]/ajax/ajax.js +++ b/[web]/ajax/ajax.js @@ -26,6 +26,15 @@ function decode( uri ) { return uri; } +// Check data is JSON +function isJSON(str) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; +} function AJAXRequest( method, url, data, process, async, dosend) { var self = this; @@ -84,7 +93,7 @@ function AJAXRequest( method, url, data, process, async, dosend) { } self.AJAX.open(method, url, async); - + if (method == "POST") { //self.AJAX.setRequestHeader("Connection", "close"); // seems to cause issues in IE self.AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); @@ -96,6 +105,9 @@ function AJAXRequest( method, url, data, process, async, dosend) { // you'd do this to set special request headers if ( dosend || typeof dosend == 'undefined' ) { if ( !data ) data=""; + if (method == "POST" && isJSON(data)) // change content type + self.AJAX.setRequestHeader("Content-Type", "application/json"); + self.AJAX.send(data); } return self.AJAX;