js files are loading in unreadable format - javascript

I was working on a Web App. I used a "✗" UTF-8 character as a delete button. Eclipse asked me to save file in UTF-8 format i told yes. Everything worked fine. But next day when i ran the app again it is throwing exception "Uncaught SyntaxError: Unexpected token ILLEGAL". When i checked it, all javascript file is loading in unreadable format. See image below.
I tried to replace that character with its UNICODE "✗" and saved all js files in default encoding, but didn't help.
Do anyone know why is this happening?

It sounds like you saved in a different text format than you loaded it and/or loaded it in a different text format that you saved it. Without recommending a tool, I would see if you can use something to change the code-page/text-format and then try stuff.
However, seeing as what you are showing on teh screen is 3rd part stuff, you could just more easily re-download it where you got it the first time, or perhaps unpack it if you saved the installer/zip-file.

Related

WordPress loading javascript with strange character set

I'm using WordPress 5.1 with Yoast SEO. Yoast SEO relies on the file components.js which is throwing the following error in the console (I've edited this for brevity - it's a very long string)
Uncaught SyntaxError: Invalid regular expression:
/[A-Za-zªµºÀ-ÖØ-öø-ƺƻƼ-Æ¿Ç€-ǃDŽ-ʓʔʕ-ʯʰ-ʸʻ-ËË-Ë‘Ë -ˤˮͰ-ͳͶ-ͷͺͻ-ͽͿΆΈ-ΊΌΎ-Î
The identical string does not appear in the file, though the file does include the following line when looking with a text editor:
["+"A-Za-zªµºÀ-ÖØ-öø-ƺƻƼ-Æ¿Ç€-ǃDŽ-ʓʔʕ-ʯʰ-ʸʻ-ËË-Ë‘Ë -ˤˮͰ-ͳͶ-ͷͺÍ
The line looks like this when looking through the webhost control panel:
["+"A-Za-zªµºÀ-ÖØ-öø-ƺƻƼ-ƿǀ-ǃDŽ-ʓʔʕ-ʯʰ-ʸʻ-ˁː-ˑˠ-ˤˮͰ-ͳͶ-ͷͺͻ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁ҂Ҋ-ԯԱ-Ֆՙ՚-՟ա-և։ःऄ-हऻ
The only odd thing is that the database had a mix of character sets (latin1, utf8 and utf8mb4) which I have attempted to fix and all tables now use utf8mb4_uncode_ci (this was chosen as it was the most common character set in the db).
There is also a mix of InnoDB and MyISAM table types. The site has a number of  characters around the site which is a common indicator of character set issues as far as I can tell.
So I'm guessing for some reason WordPress is loading the javascript file with the incorrect character set which is creating errors.
Is there a way to fix this? I'm a bit baffled.
Fixed.
This was due to blog_charset being set to UTF-7 in wp_options. Changing this to UTF-8 has solved the problem

Uncaught SyntaxError: Unexpected token ILLEGAL - when splitting up a file

I have one big file that consists of HMTL, Javascript and CSS and I wish to split it up to make it more managable. But when I split the HTML file up and save it as seperate HTML, Javascript and CSS files I get the error :
Uncaught SyntaxError: Unexpected token ILLEGAL
When I click on the error it takes me to the file in the browser and my file consists of only Chinese symbols.
I have tried finding the answer and apparently I have hidden characters in my code but how am I meant to find these ?
What can I do to fix this issue ?
Mojibake like this can occur when the program reading in a file is unable to figure out what kind of encoding a file is using and guesses the encoding incorrectly. It could be that you have a weird character lurking in your file somewhere that is completely throwing off the encoding detection.
Some encoding schemes provide a way to mitigate this problem by using a BOM, which is a short marker at the beginning of the file that indicates the type of encoding that the file uses. BOMs have advantages and disadvantages, but one big advantage is that they firmly establish a file's encoding so that the program loading the file doesn't have to guess what the encoding is. It sounds like including the BOM in your file remedied your issue.
For more information on encoding, see:
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

\u00C2 is not defined error in javascript?

I got this error on following line.
$j(id).dateplustimepicker( "setTime" ,timeVal);
Can you please help me to solve this error?
The error is probably not in this line because no string constants are evaluated there. You wouldn't get this error if, for example, id contained the value.
When you get the error again, open the JavaScript console of your browser and look at the complete stack trace. The innermost frame is where you need to be looking.
[EDIT] Since you found the character in jquery-dateplustimepicker.js, this points to the real cause of the problem.
Every text file on your computer has an encoding. But there is no way to tell which one. The problem you have means: Your text/JS file is in UTF-8 encoding but your web server sends it to the browser with a different encoding. The browser then tries to read it but finds odd characters -> error.
Another reason for the error is that someone edited the file, using the wrong encoding. That can happen on Windows, for example, when you load the file with Cp-125x and saves it as UTF-8.
To check, download the file from the web server and do a binary compare with the original.
I got the answer but i forgot to upload here....Actually i got this problem because, There is  character is present in standard library file of jquery. File name is jquery-dateplustimepicker.js. The character either need encoding otherwise, it creates problem. The character must replace with white space instead of Â.

Strange result when reading data from browser cache

In an experimental extension I am working on I use a function to get the source of a webpage and assign it to a variable. It worked perfectly fine. However I want to change the way it works and get the content from a txt file.
I am hosting a txt file like: http//1.2.3.4/1.txt.
What I want is to assign the contents of this txt file to a variable.
Function is here: http://jsfiddle.net/qumsm/.
(Function is not mine. I got it from another extension xpi which I cant remember right now. Respects to the coder of it.)
The function produces "ÿþP" this result which I dont get.
That's a byte order mark, the file you are looking at seems to be using UTF-16 LE encoding. You need to use nsIConverterInputStream instead of nsIScriptableInputStream when reading in that data and specify the correct encoding to convert from. nsIScriptableInputStream is only useful when reading in ANSI data, not Unicode. See code example on MDN.

JSON.parse Issues

so, I am working on a website for a client, a friend of mine.
He sells geckos, and he has made a website for himself, and his sales partner, and I am doing a lot of javascript work for him, IE AJAX, etc... Well, I got to the available lizard page for him, and I am making a sort of dynamic gecko selection system. The way this script is supposed to work is, fetch a JSON file (here) which is perfectly good JSON, and then parse the values in to multiselects. I'm using the jQuery.get function to do this. All goes well until I try parsing the JSON data, and the browser, firefox, throws the error "Syntax Error: JSON.parse", and chromium throws the error "Unexpected Token", the problem also occurred with
The error is thrown on line 219 of js.js,
jQuery.parseJSON().
the issues are in the function drawCat(data), the page this code is in use on is Here
I hope that this is a quality question, I'm really quite tired to be coding right now, it pretty late.
Actually that is not valid JSON. It's easy to check at http://jsonlint.com/. The error is that the root should be either one JSON object or an array. Now you have several JSON objects as roots.
Update: Danjah is also correct. After you fix this the problem he highlights will also cause invalid JSON. so you need to fix both.
I don't think its valid, there's a bunch of missing commas part way down the file, screenshot attached as no line numbering.

Categories

Resources