How would pass the parameter into “foodName” from the function that sends the url and id? i.e. could you do something like the function:
call(‘/url/to/foodlist’, “foodList”, “food”);
and replace
var input = item.food;?
Below is working code but would like a more general function then having to use part of name in the function (replace foodName so that it isn’t in this function)
function call(url, id){
var string = '';
$.ajax({
type: "GET",
url: url,
success: function (item)
if (item != '') {
var input = item.foodName;
for (var i = 0; i < input.length; i++) {
string += = '<option value=' + input[i].name + '">' + input[i].name + '</option>';
}
$('#' + id). append(string);
}
});
call(‘/url/to/foodlist’, “foodList”);
1 Answer