melihorhan
melihorhan

Reputation: 198

SCRIPT1002 :Syntax error - IE10

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.

JavaScript critical error at line 2, column 1 in .........
SCRIPT1002: Syntax error

My jquery script file have set in Master page.

<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?

Upvotes: 2

Views: 31631

Answers (5)

Adithya Baddula
Adithya Baddula

Reputation: 95

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.

Upvotes: 0

Perseus
Perseus

Reputation: 350

Excuse me, I do not know English well.

I think there are some problem in your code.

  1. Use single quote(') instead of double quote(") before and after of server-side assignment; Because ResolveUrl method use double quote for its string argument and this sequence of double quotes, is against of XHTML Well-Form ness rules.

  2. Use equal sign(=) instead of hash sign(#). Hash sign should use in data-binding expressions.

  3. You can pass the full resource path, to ResolveUrl method as its argument.

  4. If the Scripts folder 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 src attribute.

  5. To ensure the accuracy and integrity of jQuery, download it again from its official website.

  6. There is some JavaScript compatibility issues in IE 10. Use X-UA-Compatible meta tag to regulate 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:

Upvotes: 3

anu
anu

Reputation: 315

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

<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.

Upvotes: 2

Bas van Rossum
Bas van Rossum

Reputation: 487

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 is working in chrome, Firefox en IE 11.

For more information and browser compatibility see: https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Statements/const

Upvotes: 5

subsci
subsci

Reputation: 1740

The complete text of the SCRIPT1002 message provides a clue, namely, Syntax error script section:

JavaScript critical error at line x, column y in siteZ.domainQ/mypage SCRIPT1002: Syntax error script section

For me, my _Layout.cshtml or Index.cshtml, had references to virtual paths that did not exist for scripts or styles.

<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.

Please refer to Microsoft documentation about bundling, minification, and optimization for more information.

Upvotes: 5

Related Questions