diff --git a/admin.php b/admin.php index 0b46457..fc34de5 100644 --- a/admin.php +++ b/admin.php @@ -24,7 +24,8 @@ $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = (string)($_POST['action'] ?? ''); - $isAjax = (string)($_POST['ajax'] ?? '') === '1'; + $isAjax = (string)($_POST['ajax'] ?? '') === '1' + || strtolower((string)($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '')) === 'xmlhttprequest'; try { if ($action === 'create_section') { @@ -326,7 +327,7 @@ function nextUniqueCodeName(string $base): string -
+

@@ -445,8 +446,22 @@ function nextUniqueCodeName(string $base): string try { if (ajaxInput) ajaxInput.value = '1'; const fd = new FormData(form); - const r = await fetch(form.action, { method: 'POST', body: fd }); - const j = await r.json(); + const r = await fetch(form.action, { + method: 'POST', + body: fd, + headers: { + 'X-Requested-With': 'XMLHttpRequest', + 'Accept': 'application/json' + } + }); + + const raw = await r.text(); + let j = null; + try { + j = JSON.parse(raw); + } catch { + throw new Error(raw.slice(0, 180) || 'Некорректный ответ сервера'); + } if (!r.ok || !j.ok) { throw new Error(j?.message || 'Ошибка сохранения');