找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 6639|回复: 85

OpenWrt luci 显示正在收集数据解决办法,json 解析方式的锅

  [复制链接]
本帖最后由 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
我的恩山、我的无线 The best wifi forum is right here.
也遇到了这个问题,看下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

感谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

看看是什么
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

感谢分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

RE: OpenWrt luci 显示正在收集数据解决办法,json 解析方式的锅 [修改]
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

支持一下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

看看学习一下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

我学习一下。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

遇到这情况,我清理一下浏览器缓存,就可正常显示。

点评

我一开始也能通过这种方式偶尔解决,但是后面发现不能根除就进一步探索直至现在的源码改动,目前没有什么问题。一次改动,终身受益了属于是。  详情 回复 发表于 2022-7-25 08:59
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

按照你的办法搞定了,强
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

看看看看   
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

来自手机 | 显示全部楼层
学习一下     
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

看看是什么
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

楼主辛苦了,谢谢楼主分享。

我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

欢迎大家光临恩山无线论坛上一条 /1 下一条

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-29 04:34

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表