user38578
user38578

Reputation: 87

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?

Upvotes: 3

Views: 1329

Answers (2)

Owen
Owen

Reputation: 84493

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 :)

Upvotes: 2

Berzemus
Berzemus

Reputation: 3658

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.

Upvotes: 6

Related Questions