When using ajax, I receive a string as the response.
I am trying to convert this response text into a JSON object for further processing.
I have attempted using eval and also , but neither method seems to work...
What should I do next?
Here is my code snippet:
function handleResponse() {
if (httpa.readyState == 4) {
var response = httpa.responseText;
if (response != 'empty') {
alert(response);
var foo = eval('(' + strJSON + ')');
alert(foo);
}
}
}
// The response alerts the following JSON data
[{
"id": "1",
"name": "Pepsodent 100g",
"selling_price": "28.75"
}, {
"id": "2",
"name": "Pepsodent 40g",
"selling_price": "18.90"
}, {
"id": "3",
"name": "Pepsodent brush",
"selling_price": "19.50"
}]