JQuery and Unicode characters

I am invoking a .txt file from jQuery ajax. It has some special characters, such as ± . This ± is a separator for a set of arrays; The data I want to split and paste into a JavaScript array.

It is not regarded as a symbol ± when interpreted as follows.

How to get this data in the same way as the contents of the browser?

+3
source share
2 answers

you can use the escape() value to split the string. for ± I found two values ​​(maybe there are more?).

 var string = escape('test±test2±test3'); var split = string.split('%C2%B1'); alert(split); // test,test2,test3 // %B1%0A is the value i found for ± // %C2%B1 is the value escape() gives me when i just copy and paste that char :) 
+2
source

Why don't you encode a text file using JSON ? Much simpler as it is already javascript.

Use the JQuery getJSON () method, and the contents of the file will be directly parsed in the array.

+6
source

All Articles