I returned from PHP array with two elements through JSON , but the " data.length " does not work . How can I get the size of the array in JS ? If I turn it to one of the elements in the array ( data.name.length ) returns the number of elements in STRING .
for ($i = 0; $i < $result; $i++) {
$img_name ['id'] = $get_img_id[$i]['id'];
$img_name ['name'] = $get_img_id[$i]['id'];
}
return json_encode($img_name);
js:
$.ajax({
url: "upimage",
dataType: "json",
type: "POST",
data: formData,
success: function(data) {
//$.each(data, function(i) {
$("#all_files").val(data + " ,");
for ( var i = 0, l = data.length; i < l; i++ ) {
$(".returns_img").append("<div class='img_ls' id='" + i + "'><img src='/img/" + data['name'][i] + "'><button class='dell_img' id='"+ i +"'>מחק</button><br><button class='add_img' id='"+ i +"'>הוסף לכתבה</button></div>");
}
},
cache: false,
contentType: false,
processData: false
});