If you truly just need to stripe the tables odd/even rows, could you not just add this to your css for the page:
#table_selected tbody tr:nth-child(odd){ background-color: green; }
#table_selected tbody tr:nth-child(even){ background-color: yellow; }
If you need the classes, as Arun P Johny suggests in the comments, you update your script like this:
$('#table_selected tbody').empty(); // empty the table
$.ajax({ // fetch new data and insert into new rows
...
success: function(data){
$.each(data, function(i, array){
$('#table_selected tbody').append('<tr><td>'+array['name']+'</td></tr>');
});
$("#table_selected tbody tr:nth-child(odd)").addClass("odd");
$("#table_selected tbody tr:nth-child(even)").addClass("even");
}
});
or like this (more analogous to your php way):
$('#table_selected tbody').empty(); // empty the table
$.ajax({ // fetch new data and insert into new rows
...
success: function(data){
$.each(data, function(i, array){
$('#table_selected tbody').append(
$('<tr><td>' + array['name'] + '</td></tr>')
.addClass(i % 2 ? 'odd' : 'even')
);
});
}
});