jQuery SCRIPT1002:语法错误 - IE10
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14448196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SCRIPT1002 :Syntax error - IE10
提问by melihorhan
I am using .Net 4.0 freamworok on Visual Studio 2012. My web site I first started my website gives the following error on internet explorer 10. Other browsers(Google Chrome, Firefox..) is working correctly.
我在 Visual Studio 2012 上使用 .Net 4.0 freamworok。我的网站我第一次启动我的网站在 Internet Explorer 10 上出现以下错误。其他浏览器(Google Chrome、Firefox ..)工作正常。
JavaScript critical error at line 2, column 1 in .........
SCRIPT1002: Syntax error
第 2 行第 1 列中的 JavaScript 严重错误……
SCRIPT1002:语法错误
My jquery script file have set in Master page.
我的 jquery 脚本文件已在母版页中设置。
<head runat="server">
<script src="<%# ResolveUrl("~/") %>Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
I could not figure out the problem. Can you help me?
我无法弄清楚问题所在。你能帮助我吗?
回答by subsci
The complete text of the SCRIPT1002 message provides a clue, namely, Syntax error script section:
SCRIPT1002 消息的完整文本提供了一个线索,即语法错误脚本部分:
JavaScript critical error at line x, column y in siteZ.domainQ/mypage SCRIPT1002: Syntax error script section
在 siteZ.domainQ/mypage SCRIPT1002 中第 x 行第 y 列出现 JavaScript 严重错误:语法错误脚本部分
For me, my _Layout.cshtml or Index.cshtml, had references to virtual paths that did not existfor scripts or styles.
对我来说,我的 _Layout.cshtml 或 Index.cshtml 引用了脚本或样式不存在的虚拟路径。
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Bubble</title>
@Styles.Render("~/Content/ErrorPathDoesNotExist/css")
</head>
Or
或者
@section Scripts{
@Scripts.Render("~/bundles/ErrorPathDoesNotExist")
}
I solved my error by removing or correcting the invalid virtual paths in the @Styles.Render or @Scripts.Render statements.
我通过删除或更正 @Styles.Render 或 @Scripts.Render 语句中无效的虚拟路径解决了我的错误。
Please refer to Microsoft documentation about bundling, minification, and optimization for more information.
有关更多信息,请参阅有关捆绑、缩小和优化的 Microsoft 文档。
回答by Bas van Rossum
Probably you already solved your problem. But there is still no accepted answer. So here is an another one.
可能你已经解决了你的问题。但仍然没有公认的答案。所以这是另一个。
I had the same error when i was using const
in my javascript file. When i changed const IDLE = 0;
to var IDLE = 0;
my problem was solved.
当我const
在我的 javascript 文件中使用时,我遇到了同样的错误。当我改变了const IDLE = 0;
对var IDLE = 0;
我的问题得到解决。
Const is working in chrome, Firefox en IE 11.
Const 在 chrome、Firefox en IE 11 中工作。
For more information and browser compatibility see: https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/const
有关更多信息和浏览器兼容性,请参阅:https: //developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/const
回答by Perseus
Excuse me, I do not know English well.
对不起,我不太懂英语。
I think there are some problem in your code.
我认为您的代码中存在一些问题。
Use single quote(')instead of double quote(")before and after of server-side assignment; Because ResolveUrlmethod use double quotefor its stringargument and this sequence of double quotes, is against of XHTML Well-Form ness rules.
Use equal sign(=)instead of hash sign(#). Hash sign should use in data-bindingexpressions.
You can pass the full resource path, to ResolveUrlmethod as its argument.
If the Scriptsfolder is in the root of the website, there is no need to use ResolveUrl; you can just use "/Scripts/jquery-1.7.2.min.js"as value of the srcattribute.
To ensure the accuracy and integrity of jQuery, download it again from its official website.
There is some JavaScript compatibility issues in IE 10. Use X-UA-Compatiblemeta tag to regulate IE.
在服务器端赋值前后使用单引号(')而不是双引号(");因为ResolveUrl方法对其字符串参数使用双引号,并且这个双引号序列违反了 XHTML Well-Form ness 规则。
使用等号(=)而不是井号(#)。哈希符号应用于数据绑定表达式。
您可以将完整的资源路径传递给ResolveUrl方法作为其参数。
如果Scripts文件夹在网站的根目录下,则不需要使用ResolveUrl;您可以使用“/Scripts/jquery-1.7.2.min.js”作为src属性的值。
为保证jQuery的准确性和完整性,请从其官网重新下载。
IE 10 中存在一些 JavaScript 兼容性问题。使用X-UA-Compatible元标记来规范 IE。
Your code after apllying the previous points:
应用前几点后的代码:
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script src='<%= ResolveUrl("~/Scripts/jquery-1.7.2.min.js") %>' type="text/javascript"></script>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
Or (without server-side path resolution)
或者(没有服务器端路径解析)
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<script src="/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
Good Luck!
祝你好运!
Some Helpful Links:
一些有用的链接:
回答by anu
The way I solved it:-
我解决它的方式:-
1) removed some unused javascript code in my cshtml. 2) correct the script links to check if they are pointing to libraries that exist. 3) I was calling some javascript which did not exist like in Ajax.BeginForm , OnSuccess = "CloseWindow()", and CloseWindow() didn't exist,so either add the function or remove it. 4) Added this piece of code in web.config
1) 在我的 cshtml 中删除了一些未使用的 javascript 代码。2) 更正脚本链接以检查它们是否指向存在的库。3) 我正在调用一些不存在的 javascript,如 Ajax.BeginForm ,OnSuccess = "CloseWindow()",并且 CloseWindow() 不存在,所以要么添加函数,要么删除它。4)在web.config中添加了这段代码
<location path="~/Scripts">
<system.web>
<authentication mode="None" />
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location>
I am not sure if doing the fourth step is required or not. But one of the posts in stack overflow says :The error was because the browser need to access Javascript in the script folder. My project was asp.net MVC with entity framework in visual studio 2013. Hope this helps.
我不确定是否需要执行第四步。但是堆栈溢出中的一篇帖子说:错误是因为浏览器需要访问脚本文件夹中的 Javascript。我的项目是在 Visual Studio 2013 中带有实体框架的 asp.net MVC。希望这会有所帮助。
回答by Adithya Baddula
I also had the same problem with my application. I removed unused script files from my ValidationScriptsPartial.cshtml page. I am developing Asp.Net Core App.
我的应用程序也遇到了同样的问题。我从我的 ValidationScriptsPartial.cshtml 页面中删除了未使用的脚本文件。我正在开发 Asp.Net Core App。