Reputation: 15070
I have a .csv
file. I grab the file using jQuery.get()
.
$.get("data.csv", function(data) {
console.log(data)
}, "text")
Later I want to save the file in an xml.
Now my problem is the datatype of my text.
What I have Å, ë, ö, etc.
What I output �, �, �, �
How can I get the correct format of the text from a .csv file into javascript?
My meta charset is OK: <meta charset="utf-8">
But notice that I don't display the output of the csv file, I just add some more info and save it in an xml.
When I console.log the output I see these � chars. The same when I save it in the xml. But in my csv file I have the correct char.
I just found this awesome tool. It is in AS3.
When I insert Å ë ö
I need the output of escape()
.
When I use javascript.escape() for Å
I get weird chars like %uFFFD
instead of %C5
so I guess my script tries to escape �
to %uFFFD
Here the solution for people who have the same problem.
$.ajaxSetup({
'beforeSend' : function(xhr) {
xhr.overrideMimeType('text/html; charset=iso-8859-1');
}
})
$.get("data.csv", function(data) {
console.log(data)
}, "text")
Upvotes: 4
Views: 1158
Reputation: 26312
you need to replace special characters with ISO Latin codes. for more reference check this link: http://www.utexas.edu/learn/html/spchar.html
Upvotes: 1
Reputation: 85
Use one of the escape sequences in the string. For instance,The escape sequences in Javascript all begin with the backslash character, . This character lets the application processing the string know that what follows is a sequence of characters that need special handling.
Upvotes: 0
Reputation: 388316
Try adding the following to the page's header
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
Upvotes: 0