This is my code
controller = $("#src_controller").val();
source_id = '#' + $("#src_filter_tags").val();
$.ajax({
type: "GET",
data:"id=" + $(this).data('tagId'),
dataType: "json",
url: "index.php?controller=" + controller + "&action=FindByTag",
success: function(response){
var resultArray = [];
$.each(response, function(k, v) {
resultArray.push(v.*);
});
console.log('#' + $("#src_filter_tags").val());
$(source_id).val(resultArray);
return 1;
},error: function() {
console.log("error");
}
});
What I want is on the line resultArray.push (v. *); the asterisk is the name of the field that I bring from the database.
I want it to change dynamically, that is, assign a variable to that asterisk so that with each iteration of each I take a different variable.
Another solution would be to get the first value of what I get for JSON.
The problem is that depending on which table in my database asks the fields ids are different.
For example
Table1 = > table_id1 Table2 = > table_id2
So what I want to do is variable = table_id1 or table_id2 resultArray.push (v.variable);
I've managed to do it like this:
$.each(response, function(k, v) {
$.each(v, function( k, v ) {
resultArray.push(v);
return false;
});
});
I want to do this in a cleaner way