|
本帖最后由 AllenHua 于 2022-7-23 16:59 编辑
我也是前些天遇到了这个问题,最终换了一种解析 json string 到 json object 的方式解决了此问题。修改文件 /www/luci-static/resources/xhr.js
修改前
修改后
原本如下,
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
var json = null;
if (xhr.getResponseHeader("Content-Type") == "application/json") {
try {
json = eval('(' + xhr.responseText + ')');
}
catch (e) {
json = null;
}
}
callback(xhr, json);
}
}
改成
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4) {
var json = null;
if (xhr.getResponseHeader("Content-Type") == "application/json") {
console.log('I am the original xhr, ', xhr);
try {
//json = eval('(' + xhr.responseText + ')');
json = JSON.parse(xhr.responseText);
}
catch(e) {
console.debug('parsing json failed: ', e);
json = null;
}
console.log('I am the result json: ', json);
}
callback(xhr, json);
}
}
应该就可以了。现代浏览器,明显更加推荐使用 JSON.parse(JSON_STR) 来解析。
更加详细的教程我写了一篇文章,请见 https://hellodk.cn/post/1072
|
|