Browsers cannot read javascript file

By : James

I'm developing an app for the iPad in which I'm building an html file for a webview. I'm using several javascript files which I'm copying out of my resource bundle to the app's temp directory.

When I try to bring this html file up, the javascript is throwing errors. It seems that any browser sees every linked resource as a string of chinese characters. I've looked in the error consoles of Safari, Chrome and FireFox.

If I pull these files up in TextMate or any other editor, they load fine.

This is definitely a file encoding problem. The same problem occurred by loading the html up on my windows machine. Opening it up in Notepad++, I notice that it's being saved as 'UCS-2 Little Endian' after resaving it as ANSI, the Javascript runs fine. Still no idea why it's saved this way after specifying nsutf8stringencoding.

By : James


It Would be easier to answer if you share a link to one of those files. If you say the encoding is correct, it may be the server is sending wrong charset-headers.

By : Dr.Molle

The problem turned out to be simply a mismatch of encodings. While the html files were being saved as ANSI, I was trying to read them as UTF8. By switching to saving and reading as UTF8, the issue disappeared.

By : James

This video can help you solving your question :)
By: admin