I have a function that has to receive data from DB on Server and push it into the array. That is:
function Preload() {
var valueToPush = {};
var userID1 = '<?php echo $id_user;?>';
$.ajax({
url: 'TR.php',
type: 'POST',
data: {
userID1: userID1
},
success: function(data) {
var names = data
$('#result_div_id').html(data);
var json2 = $.parseJSON(data);
EntriesCount = json2.length;
$(json2).each(function(i, val) {
$.each(val, function(k, v) {
switch (k) {
case 'Name':
valueToPush.Name = v;
case 'Phone':
valueToPush.Phone = v;
}
name2.push(valueToPush);
});
});
currententry = 0;
}
});
}
}
But this code is adding an only one entry in array. Other entries are undefined... What I am doing wrong?