未捕获的语法错误:意外的令牌= [英] Uncaught SyntaxError: Unexpected token =

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

问题描述

我刚刚从使用d3.v3的缩小版本的本地副本切换到开发版本。在使用缩小版本,但使用我的本地副本 http://d3js.org/d3.v3.js给出标题中的错误,引用此行:

I just switched from using a local copy of the minified version of d3.v3 to the development version. It worked fine when using the minified version, but using my local copy of http://d3js.org/d3.v3.js gives me the error in the title, referencing this line:

var € = Math.PI, µ = 1e-6, d3_radians = € / 180, d3_degrees = 180 / €;

当我包含托管文件时,它工作正常。

When I include the hosted file, it works fine.

推荐答案

问题是你使用ISO-8859-1字符编码(通常是浏览器默认) D3必须以UTF-8编码提供。通常情况下,这是因为您在加载HTML页面顶部缺少元标记:

The problem is that you are serving D3 with the ISO-8859-1 character encoding (often the browser default), whereas D3 must be served with UTF-8 encoding. Typically this happens because you are missing a meta tag at the top of the loading HTML page:

<!DOCTYPE html>
<meta charset="utf-8">

元指定的字符集是必需的,因为 d3js.org GitHub Pages 提供,不指定字符集在Content-Type响应头中。因此,从加载HTML文档推断字符集。

The meta-specified charset is required because d3js.org is served by GitHub Pages and does not specify a charset in the Content-Type response header. The charset is therefore inferred from the loading HTML document.

如果愿意,您可以在脚本标记上指定一个charset属性。确保在测试之前清除浏览器缓存,因为缓存副本将从最初访问时保留字符编码:

If you prefer, you can specify a charset attribute on the script tag. Make sure you clear your browser cache before testing, as the cached copy will retain the character encoding from when it was originally accessed:

<script src="http://d3js.org/d3.v3.js" charset="utf-8"></script> 

缩小版本不会发生错误,因为变量名称由ASCII等效项替换。 (我不记得,如果格式字符串中的UTF-8字符同样被转义序列替换,但我仍然建议在所有情况下将D3作为UTF-8)。

The error does not occur with the minified version because the variable names are replaced with ASCII equivalents. (I don't recall offhand if UTF-8 characters in format strings are likewise replaced with escape sequences, but I still recommend serving D3 as UTF-8 in all cases.)

如果您通过在浏览器中查看源代码然后使用复制粘贴来下载D3,这也是为什么我建议您下载 d3.v3.zip

Encoding problems can also happen if you downloaded D3 by viewing the source in your browser and then using copy-paste, which is why I recommend downloading d3.v3.zip.

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

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