1未捕获的SyntaxError:JSON输入的意外结束

时间:2018-06-07 19:25:09

标签: javascript jquery requirejs

我有一个网站随机抛出此JavaScript错误。如果刷新站点,它几乎总是会发生,它会阻止站点加载。相反,你只看到一个空白的白页。

控制台声明存在" Uncaught SyntaxError:JSON输入的意外结束"在第8行的require.js中。该行显示为:

html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}

这条线路有什么问题我没看到吗?

The site

Chrome console output

Firefox console output

1 个答案:

答案 0 :(得分:0)

define("lib/config", [], function() {
    "use strict";
    var e = document.getElementById("app-config");
    return e ? JSON.parse(e.innerHTML) : {}
})

这是代码中有问题的部分。在执行此部件之前,并不总是加载app-config元素。如果可能,请将您的app-config硬编码到您的html中