From 21d7d816023fe0746f658e44b7919965941be533 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sun, 7 Feb 2021 09:28:14 -0500 Subject: [PATCH] Fixed: Settings fields being altered during save (cherry picked from commit dd61480d60e067e851982b0cc98f03f752b80673) --- frontend/src/Utilities/createAjaxRequest.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frontend/src/Utilities/createAjaxRequest.js b/frontend/src/Utilities/createAjaxRequest.js index 1b33f5a04..dac6fbd32 100644 --- a/frontend/src/Utilities/createAjaxRequest.js +++ b/frontend/src/Utilities/createAjaxRequest.js @@ -28,6 +28,15 @@ function addApiKey(ajaxOptions) { ajaxOptions.headers['X-Api-Key'] = window.Lidarr.apiKey; } +function addContentType(ajaxOptions) { + if ( + !ajaxOptions.contentType && + ajaxOptions.dataType === 'json' && + (ajaxOptions.method === 'PUT' || ajaxOptions.method === 'POST')) { + ajaxOptions.contentType = 'application/json'; + } +} + export default function createAjaxRequest(originalAjaxOptions) { const requestXHR = new window.XMLHttpRequest(); let aborted = false; @@ -46,6 +55,7 @@ export default function createAjaxRequest(originalAjaxOptions) { moveBodyToQuery(ajaxOptions); addRootUrl(ajaxOptions); addApiKey(ajaxOptions); + addContentType(ajaxOptions); } const request = $.ajax({