Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery and Unicode characters

I am calling a .txt file from a jquery ajax call. It has some special characters like ±. This ± is a delimiter for a set of array; data I want to split out and push into a JavaScript array.

It is not treated as ± symbol when interpreted like this.

How do I get that data as just like browser content?

like image 780
user38578 Avatar asked Apr 19 '26 06:04

user38578


2 Answers

Why don't you encode your text file using JSON ? Much more easier, as it already is javascript.

Use JQuery's getJSON() method, and the file contents will directly be parsed into an array.

like image 73
Berzemus Avatar answered Apr 20 '26 19:04

Berzemus


you could use the escape() value to split a 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 :)
like image 42
Owen Avatar answered Apr 20 '26 18:04

Owen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!