From 28ab21dd8d10b42b5473fd4949a25e22a98ee9cc Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Thu, 11 Jul 2019 01:24:33 +0800 Subject: [PATCH] luci-base: handle application/json replies with charset specification On my router, the response header Content-Type is `application/json; charset=UTF-8` instead of `application/json`, so almost every feature is broken. Fixes: #2851 Suggested-by: zhanhb <6323014+zhanhb@users.noreply.github.com> [reword commit subject] Signed-off-by: Jo-Philipp Wich --- modules/luci-base/htdocs/luci-static/resources/xhr.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/xhr.js b/modules/luci-base/htdocs/luci-static/resources/xhr.js index 25a90e7254..23a6700d18 100644 --- a/modules/luci-base/htdocs/luci-static/resources/xhr.js +++ b/modules/luci-base/htdocs/luci-static/resources/xhr.js @@ -88,7 +88,7 @@ XHR = function() { if (xhr.readyState == 4) { var json = null; - if (xhr.getResponseHeader("Content-Type") == "application/json") { + if (/^application\/json\b/.test(xhr.getResponseHeader("Content-Type"))) { try { json = JSON.parse(xhr.responseText); } catch(e) { json = null; } } -- 2.30.2