0

I'm facing very strange behaviour in Chrome & Mozilla from jQuery. I'm getting very generic Unexpected token ILLEGAL error on my document.ready function.

While playing with a signaturepad sample, I tried it with my own page. It is not working in Mozilla & Chrome, but is working in IE. Then I removed all references of signaturepad and put a simple one alert inside document.ready function and observed (Thanks to Chrome JavaScript Errors Notifier) Unexpected token ILLEGAL error is occurring when system try to use jQuery reference. Then I copied all the text from the sample page (a.html), where it works perfectly inside this page (b.html), and ran the page again. I'm surprised the a.html page is working fine while b.html page is throwing the error. Both pages are on the same directory and have the same content.

    <html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title> </title>
    <link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css">
    <link href="css/jquery.signaturepad.css"  rel="stylesheet">
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/jquery.mobile-1.3.1.min.js"></script>
</head>
<body>

<script>
    $(document).ready(function () {
        alert('hai');

    })

</script>

</body>
</html>
TylerH
  • 20,799
  • 66
  • 75
  • 101
Indra Bisen
  • 31
  • 1
  • 5
  • Have you accidentally pasted in some non-printing character(s)? (Are you using an editor that would show non-printing characters?) – nnnnnn Jul 05 '14 at 03:27
  • the problem might not be in the script body but in the jquery.mobile-1.3.1.min.js try importing jquery using cdn and see if any changes occur – Yehia Awad Jul 05 '14 at 04:29

2 Answers2

1

Problem fixed now. Issue was in Encoding through which file was saved. The problematic file was saved with Unicode-1200 while it should be saved with Unicode-65001.

Thanks all for answering/comments.

Regards

Indra Bisen
  • 31
  • 1
  • 5
-1

I would do a few things that may sound silly --

  • Add a <!DOCTYPE html> tag to the top -- jquery mobile likes it
  • remove the indentation in front of your <html lang="en"> tag
  • redownload or try to use a hosted jquery library (e.g. from google) to see if that's it
  • add a closing ; after your })
John C
  • 666
  • 4
  • 8