Javascript confirmation window pops up several times

I am trying to use the confirmation method, but for some reason the confirmation window appears several times. I googled and tried different things, but unfortunately I cannot get it to work properly. The code is as follows:

//user clicks on the delete button
$("#deletePopUpImage").click(function(){

        console.log("deletePopUpimageCalled");

        //get the id of the image
        id = ($(this).parent().prop("id"));

        //create the ajax request
        data = "typ=function&functionType=deleteUserImage&id="+id;

        //open the confirm box
        var r = confirm("Are you sure that you want to delete this image?");
        if (r == true) {
            console.log("loadAjaxCAlled");

            //Ajax call
            loadAjax(data);

            //hide the image and the loader
            hideImagePopup();
        } else {
            //do nothing
        }  
    });

It is strange that sometimes the confirmation window appears twice, sometimes three times, and sometimes as expected. This is why two console.logs were inserted.

"deletePopUpimageCalled" always appears only once. However, "loadAjaxCAlled" appears several times.

In the callback of the Ajax method, I just hide the thumbnail of the div.

Do you know what's wrong with my code above?

Thanks Stefan

+4
source share
2 answers

, , :

$("#deletePopUpImage").click(function(){...});

. .click(...) , .

( ), , "deletePopUpimageCalled" . , .

+1

, . Ajax div , , : none, . , divIds , .. .

0

Source: https://habr.com/ru/post/1611252/


All Articles