recurring JQuery post on modal.show

27 Views Asked by At

I just want to show a modal with a progress bar while i make a call to the server, everything works correctly, but every click on the element, sends many calls as clicks made in this element. What is wrong?

$('.tbEmail').click(function (ev) {
if ($(this).val() != '') {
    $('#loadingModal').on('shown.bs.modal', function (e) {
        $.post('/contratto/validateemail',
            {
                Email: $(this).val()
            })
            .done(function (msg) {
                if (msg.mailValid) {
                    $('#iconVerifymail').css("color", "green");
                }
                else {
                    $('#iconVerifymail').css("color", "red");
                }
            })
            .fail(function (msg) {
                $('#iconVerifymail').css("color", "red");
            })
            .always(function () {
                $('#loadingModal').modal('hide');
            });
        e.preventDefault();
    });

    $('#loadingModal').modal('show');
}
else {
    $('#iconVerifymail').css("color", "red");
}
ev.preventDefault();
});
0

There are 0 best solutions below