I am encountering an issue with the following code:
function inicioConsultar(){
$(function(){
$('#serviciosU').change(function(){
if ($('#serviciosU').val()!= "-1")
{
$.ajax({
url: "@Url.Action("ObtenerCapas")",
data: {urlServicioUsuario:$("#serviciosU :selected").val()},
dataType: "json",
type: "POST",
error: function() {
alert("An error occurred.");
},
success: function(data) {
var items = "";
$.each(data, function(i, item) {
items += "<option value=\"" + item.Value + "\">" + item.Text + "</option>";
});
$("#capas").html(items);
}
});
}
})
});
I added "inicioConsultar()" to my Index.cshtml and there seems to be an issue with the ajax call. If I remove the ajax call, everything works fine.
In the layout file, I have loaded jQuery and the index is included within that layout.
Apologies for any language mistakes in my explanation.