Gerardo
Gerardo

Reputation: 369

Ajax validation in success fail always get EmptyObject true

I have an ajax method get who call my controller. Into success function it get two arrays: eventos.asignados and eventos.noAsignados

Problem is validation always comes true, because it always send me alert, as you can see there: enter image description here

can someone explain me why it pass validation if my array is not empty?

AJAX CALL:

$.ajax({
        type: 'GET',
        url: "/Agenda/GetTareasCalendario/",
        data: {
            //data there
        },
        dataType: 'json',
        success: function (eventos) {

            refreshCalendarEvents(eventos.asignados);
            addEvents(eventos.noAsignados, true);

            if ($.isEmptyObject(eventos.asignados && eventos.noAsignados)) {
                alert('No se han encontrado resultados con los filtros seleccionados.');
            }
        }
    });
});

Upvotes: 1

Views: 21

Answers (1)

Mahesh Singh Chouhan
Mahesh Singh Chouhan

Reputation: 2588

Change your if conditions like below to check for empty objects one by one

Try this:

if ($.isEmptyObject(eventos.asignados) && $.isEmptyObject(eventos.noAsignados)) {
    alert('No se han encontrado resultados con los filtros seleccionados.');
}

Upvotes: 1

Related Questions