2
I have a function hello()
whose argument is the return of an ajax call:
function hello(msg) {
alert(msg);
}
$.ajax({
url: 'example.com',
data: data
}).done(function(resp) {
// abre_modal
// apenas no fecho (click close) da modal é que eu quero que a função abaixo seja executada
$('#myModal').on('hide.bs.modal', function() { hello(resp); });
});
But the above scenario causes a problem, the event is delegated several times, and as a consequence the function hello()
is executed the same number of times.
How do I, considering I only want to delegate the event once, but the resp
is dynamic, so that the function is executed only once, as well as the delegation of the event click close of the modal?
That’s okay because the modal only opens when ajax is
done()
. In the meantime, I’ve managed:$('#myModal').off('hide.bs.modal').on('hide.bs.modal', function() {...});
. But I’ll take yours for sure. Thank you.– Hula Hula
@Hulahula also foreheads with
.one(
, jQuery has to run Event handlers only once– Sergio
Ha good, I didn’t know that no
– Hula Hula