Solved

Javascript encoding problem

Posted on 2011-02-25
8
540 Views
Last Modified: 2012-05-11
Hello experts,
I've been learning to hate Javascript. Please help me...

I am working on a page that reads a CVS file and shows it on a text area.

The file (input.csv) is enconded on ISO-8859-1 as shown in Figure 1 and Figure 2.

My page is also encoded as ISO-8859-1 and configured to use ISO-8859-1 as shown in Figure 3.

My page read the file using the following function:

function IO(U, V) {//LA MOD String Version. A tiny ajax library.  by, DanDavis
            var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP')
                        : new XMLHttpRequest();
            X.open(V ? 'PUT' : 'GET', U, false);
            X.setRequestHeader('Content-Type', 'text/html;charset=iso-8859-1')
            X.send(V ? V : '');
            return X.responseText.toUpperCase();
      }

Figure 4 shows how the Text Area looks like when I do:
        text = IO("input.csv");
        othersConsole.value = text;

I am using Safari.

What am I missing???

Thanks!!
Rodrigo.

Figure1.png
Figure2.png
Figure3.png
Figure4.png
0
Comment
Question by:chocksmith01
  • 4
  • 3
8 Comments
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34984054
It seems to be a font family issue, where those characters are not available in the font.  Try using a different font that you know can display the characters.
0
 

Author Comment

by:chocksmith01
ID: 34986689
As you can see on Figure 2, the question mark funny char appears when we try to display ISO-8859-1 chars as UTF-8. It is not a matter of font family...
My guess is that for some reason the <meta> tag is being ignored (Figure 3).
0
 
LVL 16

Expert Comment

by:BurnieP
ID: 34987524
Hi,

Take a look at this thread : http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_22577077.html

Basically the solution was to add this as the first line :
Response.AddHeader "Content-type", "text/html; charset=iso-8859-1"

0
 

Author Comment

by:chocksmith01
ID: 34987565
Didn't I do that???
My function has: X.setRequestHeader('Content-Type', 'text/html;charset=iso-8859-1')
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 23

Expert Comment

by:wdosanjos
ID: 34987929
"iso-8859-1" defines the character encoding not the font.  The font would be 'Arial', 'Times New Roman', 'Verdana', etc.  There are different ways to define the font. It could be on your style sheet or on the tag itself, something like style="font-family:Arial".
0
 

Author Comment

by:chocksmith01
ID: 35042953
That's what I'be been trying to say.
It was nothing to do with Fonts. I do not understand why it ignores my commands and tags to use iso-8859-1 and keep using utf-8
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 125 total points
ID: 35058387
According to the documentation, the server is ultimately responsible for honoring the Content-Type set on the request header.  I think you need to check the server code/configuration.  If the server's response does not contain the Content-Type header, it seems that XMLHttpRequest assumes is UTF-8, that might be the issue here.

http://msdn.microsoft.com/en-us/library/ms536752%28v=VS.85%29.aspx

You can try the following to view the response headers:

            ...
            X.send(V ? V : '');
            alert(X.getAllResponseHeaders());
            ...
0
 

Author Closing Comment

by:chocksmith01
ID: 35107957
It did not solved the issue, but gave me good ideas to overcome the problem doing things in a different way.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now