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 multiple times, and as a consequence the hello()
function executes the same number of times.
How do I, given that 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 modal?