Chrome:未捕获语法错误:意外的输入结束 [英] Chrome: Uncaught SyntaxError: Unexpected end of input

查看:205
本文介绍了Chrome:未捕获语法错误:意外的输入结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google Chrome中加载网页时,控制台中会出现一个含糊的错误:


未捕获的语法错误:意外的输入结尾


我不知道是什么原因造成的。我如何去调试这个错误?

解决方案

这个特殊的错误是关于V8的一个令人讨厌的事实。在大多数情况下,您的JavaScript以某种方式损坏。例如,缺少一个} 或类似的东西。



给出的示例,这将产生意外的输入结束也是:

  eval('[{test:4}')//通知丢失的] 

但问题的根本原因似乎是请求的JSON网址具有内容类型 text / html / p>

尝试将内容类型设置为 text / plain 我认为应该修复问题。



尽管如此,V8可以做一个更好的工作,直接告知一个 其中 输入意外结束。


When loading my page in Google Chrome, I get a vague error in the console:

Uncaught SyntaxError: Unexpected end of input

I have no idea what is causing it. How would I go about debugging this error?

解决方案

This particular error is one annoying fact about V8. In most cases your JavaScript is broken in some way. For example missing a } or something like that.

Example given, this will yield "Unexpected end of input" too:

eval('[{"test": 4}') // notice the missing ]

But the root cause of the problems seems to be that the requested JSON url has a Content-Type of text/html which Chrome apparently tries to parse as HTML, which then results in the unexpected end of input due to the fact that the included image tags are being parsed.

Try setting the Content-Type to text/plain I think it should fix the issues.

Nonetheless, V8 could do a better Job about telling one exactly where the input ended unexpectedly.

这篇关于Chrome:未捕获语法错误:意外的输入结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆