views:

228

answers:

3

I am calling a .txt file from a jquery ajax call,

it has some special characters like "±". this ± is delimiter for a set of array...data i want to split it out and push into a js array.

but it is not treated as ± symbol when interpreted like this.

so how do i get that data as just like browser content?

+6  A: 

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.

Berzemus
+2  A: 

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

Thank you both of you :) i felt Owen's approach is easy though... but Owen the value i found for ± is %uFFFD

anyway that didn't click to my thought. thanks a lot!