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 <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-07-11 01:24:33 +08:00
parent a388be0f28
commit 28ab21dd8d

View file

@ -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; }
}