I have a script that recovers the information of a JSON as I can put so that if it has nothing the JSON does not put anything in the variable items
. This is my code:
<script type="text/javascript">
$(function () {
$("#IdPlantel").change(function () {
$.getJSON("Oferta/List/" + $("#IdPlantel>option:selected").attr("value"), function (data) {
var items;
if (data == null) {// no lo respeta
items = "";
}
else {
$.each(data, function (i, state) {
items += "<option value='" + state.Value + "'>" + state.Text + "</option>";
});
}
$("#States").html(items);
});
});
});
</script>