tags:

views:

33

answers:

2

A php script is giving this array (which has been passed through json_encode())

[{name:"a1",path:"b1"},{name:"a2",path:"b2"}]

I use the following function to retrieve the array to jquery:

$.ajax({
type: "POST",
url: "functions.php",
data: "action=" + something,
cache: false,
success: function(response) { alert(response); }
});

The problem is I get the array back as a string:

(new String("[{name:"a1",path:"b1"},{name:"a2",path:"b2"}}]"))

How can I get it to be a javascript array?

Help would be much appreciated.

+1  A: 

With JSON.parse():

function(response) { alert(JSON.parse(response)); }
Felix Kling
That was it. Thanks.
Wurlitzer
+3  A: 
$.ajax({
type: "POST",
url: "functions.php",
dataType: 'json',
data: "action=" + something,
cache: false,
success: function(response) { alert(response); }
});

Try specifying the data type as JSON.

anomareh