I retrieve some option for a select from an ajax call in json format. The code I have set up to display the new options in the select (replacing the existing ones) is the following:
success: function (data){
var $select = $('#dettaglio');
$select.html('');
$.each(data, function(key, val){
$select.append('<option id="' + val.id + '">' + val.text +'</option>');
})
}
while the json is like this:
[
{"id":"1","text":"J-Invest Spa"},
{"id":"2","text":"J-A Holding S.r.l."},
{"id":"3","text":"J-Invest Advisory & Servicing S.r.l."},
{"id":"4","text":"J-Invest Immobiliare e Consulenza S.r.l."}
]
Running this code leads to an error that is not easy to understand:
TypeError: invalid 'in' operand e
...===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=b(o);var _={}...
jQuery is throwing an error but this is not helpful to see where my code is wrong. Any hint?
datain JSON format?dataType:'json',