I create a json in php like this:
$details= array();
$ret = array();
for($i=0;$i<3;$i++) { $details["name"] = "name".$i; $ret[] = $details;}
And then return it to a jquery ajax:
echo json_encode($ret,JSON_UNESCAPED_UNICODE);
die();
In jQuery ajax:
$.ajax({
url: "index2.php?id=upload",
type: "POST",
data: new FormData($("#form")[0]),
contentType: false,
cache: false,
processData:false,
returnType:"json",
success: function(data)
{
console.log('names:'+JSON.stringify(data));
$.each(data, function(i)
{
console.log('name:'+data[i]['name']);
}
},
first console log prints,but second: I get this error:
jquery-2.2.3.min.js:2 Uncaught TypeError: Cannot use 'in' operator to search for 'length' in [{"name":"name1"},{"name":"name2"},{"name":"name3"}]
Also I try
$.each(JSON.parse(data), function(i)
{ ..}
but I print empty:
name:undefined