Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Sources Displaying Javascript in Chinese

My javascript was working properly and then all of the sudden it wasn't. Chrome give me the Uncaught SyntaxError: Unexpected token ILLEGAL error on line 1 of my JS file called para2.js. I removed script from the file except for the following and I still get the error:

$( window ).ready(function() {
});

My jQuery file is included in the head of my document:

<script src="../shared/jquery.js" type="text/javascript"></script>
<script src="js/para2.js" type="text/javascript"></script>

When I look at my js file in Chrome developer tools on the Sources tab, it displays the script in Chinese:

兪敵祲搨捯浵湥⥴爮慥祤昨湵瑣潩⡮笩⥽

When I view the source of the js file, it looks fine. I have read similar posts that say copy and pasting from JSFiddle can include some hidden characters that may cause it, but I have started from scratch writing this file from a blank text file and copy and pasting nothing. It is strange that it was working and now it is not. Did my server get hacked or something? And help is appreciated.

like image 958
vanreus Avatar asked Mar 20 '15 15:03

vanreus


People also ask

How do I change DevTools Language in Chrome?

Chrome DevTools now supports more than 80 languages, allowing you to work in your preferred language! Open Settings, then select your preferred language under the Preferences > Language dropdown and reload DevTools.

How do I reset DevTools?

Reverting all DevTools settings to the defaults ) button, or press F1 . On the left, make sure the Preferences page is selected. At the bottom of the Preferences page, click the Restore defaults and refresh button.

What Language does chrome console use?

The main uses of the Chrome DevTools Console are logging messages and running JavaScript.


2 Answers

You should use the charset attribute to indicate which charset you are using.

<script src="../shared/jquery.js" type="text/javascript" charset="UTF-8">
like image 151
Breno Marini Avatar answered Nov 07 '22 05:11

Breno Marini


I had the same problem with jquery-1.5.1.min.js. Chrome kept evaluating it as Chinese (scripts worked fine in IE). I finally solved the problem by re-encoding the .js files using "convert to UTF-8" in Notepad++. Note, not UTF-8 without BOM, but UTF-8.

like image 42
Amit Kohli Avatar answered Nov 07 '22 05:11

Amit Kohli