Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing quotation marks from responsetext property

I am trying to remove quotation marks from the responseText property of a XMLHttpRequest object.

My output is :

"[{"data":[[0,28]],"label":"Atyc-1"},{"data":[[0,13]],"label":"Atyc-10"},{"data":[[0,16]],"label":"Atyc-11"},{"data":[[0,17]],"label":"Atyc-2"},{"data":[[0,5]],"label":"Atyc-3"}]"

what I need is:

[{"data":[[0,28]],"label":"Atyc-1"},{"data":[[0,13]],"label":"Atyc-10"},{"data":[[0,16]],"label":"Atyc-11"},{"data":[[0,17]],"label":"Atyc-2"},{"data":[[0,5]],"label":"Atyc-3"}]
like image 981
pln Avatar asked Mar 07 '13 16:03

pln


2 Answers

Try this:

JSON.parse(xhr.responseText);

Explanation:

It's a JSON response, which means the server is responding with JSON format. In order to use it properly in JavaScript, you need to parse the string as JSON using the JSON.parse() function. That will convert the JSON object to the response you need.

like image 122
Samuel Imolorhe Avatar answered Nov 15 '22 09:11

Samuel Imolorhe


responsetext.substring(1, responsetext.length - 1);

This will return the string with the first and last characters removed.

like image 33
Matt Cain Avatar answered Nov 15 '22 09:11

Matt Cain