Kev_T
Kev_T

Reputation: 705

AJAX fires success twice

I have the following Javascript code. For some reason the ajax success option fires twice, I get two identical alerts.

if (message =="") {
    $.ajax({
        url:  '/dev/php/register.php',
        type: 'POST',
        data: {firstname:voornaam,lastname:achternaam,email:email,password:wachtwoord,gender:gender,date:datum},
        success: alert("Account aangemaakt")
        })
}
else {
        showSnackBar(message);
        return false;
     }

Upvotes: 3

Views: 609

Answers (2)

Kev_T
Kev_T

Reputation: 705

I just fixed it by renaming the function to something random like wowwat. I don't know why this works.

    if (message =="") {
    $.ajax({
        url:  '/dev/php/register.php',
        type: 'POST',
        data: {firstname:voornaam,lastname:achternaam,email:email,password:wachtwoord,gender:gender,date:datum},
        success: function(wowwat)
        { 
            alert("Account aangemaakt");
        }
})
}
else {
        showSnackBar(message);
        return false;
     }

Upvotes: 0

Steven Johnston
Steven Johnston

Reputation: 1849

Its calling the alert function when it is being set up and again when success is fired. try

success: function(data){
    alert("Account aangemaakt");
}

Upvotes: 7

Related Questions