luci-base: handle application/json replies with charset specification
authorJo-Philipp Wich <jo@mein.io>
Wed, 10 Jul 2019 17:24:33 +0000 (01:24 +0800)
committerJo-Philipp Wich <jo@mein.io>
Fri, 26 Jul 2019 10:46:39 +0000 (12:46 +0200)
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>
modules/luci-base/htdocs/luci-static/resources/xhr.js

index 25a90e7254ffbcccb203c55e068b7dc8840ca0b2..23a6700d18774b077da6b6b5c67e3b170c050b7e 100644 (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; }
                                }