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

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

问题描述

在 Google Chrome 中加载我的页面时,我在控制台中收到一个模糊的错误:

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

Uncaught SyntaxError: Unexpected end of input

Uncaught SyntaxError: Unexpected end of input

我不知道是什么原因造成的.我将如何调试此错误?

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

推荐答案

这个特殊的错误是关于 .在大多数情况下,您的 JavaScript 以某种方式损坏.例如缺少 } 或类似的东西.

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 ]

但问题的根本原因似乎是请求的 JSON url 具有 text/htmlContent-Type,Chrome 显然试图将其解析为 HTML,由于正在解析包含的图像标签,这会导致输入意外结束.

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.

尝试将 Content-Type 设置为 text/plain 我认为它应该可以解决问题.

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

尽管如此,V8 可以更好地告诉人们输入意外结束的哪里.

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

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

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