From: Jo-Philipp Wich Date: Wed, 10 Jul 2019 17:24:33 +0000 (+0800) Subject: luci-base: handle application/json replies with charset specification X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=28ab21dd8d10b42b5473fd4949a25e22a98ee9cc;p=oweals%2Fluci.git 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 --- diff --git a/modules/luci-base/htdocs/luci-static/resources/xhr.js b/modules/luci-base/htdocs/luci-static/resources/xhr.js index 25a90e725..23a6700d1 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; } }