I have a registration screen where the user can add or not phone numbers. I am adding fields to insert the phone dynamically, but one of these fields is a select that will bring data from the database. My jquery is hitting the controller and it is returning the list with the database data, but it is not populating the select, I do not know where the error is. in console.log there is nothing.
Html
<button type="button" id="btnAddTelefone">Adicionar</button>
<table id="tblTelefones">
<thead>
<tr>
<td>DDD</td>
<td>Numero</td>
</tr>
</thead>
<tbody></tbody>
</table>
JQuery
$("#tblTelefones tbody").append("<tr>" +
"<td><select id='ddlTipoTelefone' name='ddlTipoTelefone'><option value>---Selecione um Tipo---</option></select></td>" +
"<td><input id='txtDDD'></td>" +
"<td><input id='txtNumero'></td>" +
"<td><input id='txtRamal'></td>" +
"<td class='bto'><button type='button' class='bt-salvar'>Salvar</button></td></tr>");
$.ajax({
type: "get",
url: "/Prestador/GetAllTipoAcessoTelefone",
data: { tipos: $("#ddlTipoTelefone").val() },
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function (obj) {
if (obj != null) {
var data = obj.data;
var selectbox = $('#ddlTipoTelefone');
alert(data);
//selectbox.find('option').remove();
$.each(data, function (i, d) {
$('<option>').val(d.TipoId).text(d.TipoNome).appendTo(selectbox);
});
}
}
});
Controller
[HttpGet]
public JsonResult GetAllTipoAcessoTelefone()
{
var lista = _commonService.GetAllTipoAcessoTelefonico()
.Select(x => new { x.TipoId, x.TipoNome});
return Json(lista, JsonRequestBehavior.AllowGet);
}
Does anyone know what it can be?
Note: the alert (date) in the middle appears "undefined".