質問

I´ve a strange problem. I am providing a link which sends an ajax request to delete a user. If the User clicks a link for the first time and confirms the confirm box the ajax function is triggered. but if the user after that again clicks a link with class delUser, nothing happens. No confirm Box nothing, It seems the click function is ignored than. I found out if I cut the part with the confirmbox everything works fine.

Whats wrong with this confirm?

jQuery(".delUser").click(function(){       
    // open confirm Window
    confirm = window.confirm("Nutzer wirklich löschen?");
    User = $(this).attr("data-link");

    if(confirm == true){

            jQuery.ajax({
            type: "POST",
            url: "/Admin/DelUser.php",
            data: { where: User },
            success: function(retData){
                    jQuery.noticeAdd({text: "" + retData + "",
                    stay: false, 
                    type: 'error'
                });                             
                }
            }); 
            $(this).closest('tr').remove(); 

            } else {
                   talk("Nutzer wurde nicht gelöscht");
            }         
    });

Kind regards,

Tony

役に立ちましたか?

解決

Because you are overwriting confirm.

This line:

confirm = window.confirm("Nutzer wirklich löschen?");

is equal to

window.confirm = window.confirm("Nutzer wirklich löschen?");

One of the reasons why using globals is a very bad idea. When you are declaring a variable, please always use var, so it will not be global:

var confirm = window.confirm("Nutzer wirklich löschen?");

The same would apply to User. You should declare it like:

var User = $(this).attr("data-link");

他のヒント

Try this:

jQuery(".delUser").click(function(){       
User = $(this).attr("data-link");

if(window.confirm("Nutzer wirklich löschen?")){

        jQuery.ajax({
        type: "POST",
        url: "/Admin/DelUser.php",
        data: { where: User },
        success: function(retData){
                jQuery.noticeAdd({text: "" + retData + "",
                stay: false, 
                type: 'error'
            });                             
            }
        }); 
        $(this).closest('tr').remove(); 

        } else {
               talk("Nutzer wurde nicht gelöscht");
        }         
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top