Why is my AJAX running 4 times

unm4sk

http://i.imgur.com/eFjV8Uv.png

$("#login").on('click', function () {
    $(".login .col2, .login .signin, .login .close").fadeOut(500, function () {
        $(".login .spinner").fadeIn(500);
        var username = $("#username").val();
        var password = $("#pw").val();
        var data = "username="+username+"&password="+password;
        $.ajax({
            url: './api/prijava',
            method: 'POST',
            data: data,
            dataType: 'json',
            success: function(data) {
                if(data.odg == 1) {
                    $(".login .spinner").fadeOut(500, function() {
                        $(".login .msg").append('Prijava uspješna').fadeIn(500, function() {
                            window.location = "./";
                        });
                    });
                } else if(data.odg == 2) {
                    $(".login .msg").css('background-color', 'rgba(0, 255, 0, 0.5)').append('<span>Prijava uspješna! Dobrodošli...</span>').fadeIn(500, function() {
                        window.location = "./?first=true";
                    }); 
                }
            }, 
            error: function(err) {
                console.log(err);
            }
        });
    });
});

Screenshot shows successful login (local language) but it should show it once, rather than 4 times. How can I make it load once and that's it?

Explosion Pills

The callback to fadeOut will run once per selected element. Instead you could use the promise to since when it resolves it only runs once:

$(selector).fadeOut(500).promise().then(function () {
    // do ajax call here
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why my effect is running serveral times after action is called?

From Dev

My ajax request submits once, then twice, then 4 times and keeps doubling

From Dev

Why my comments are repeating 3 or 4 times each ?

From Dev

Why is my code returning a list of the same object 4 times?

From Dev

Why my angualar.js filter runs 4 times?

From Dev

Why does my Surface Pro 4 write as if the ink was running out?

From Dev

Why my Ajax not working?

From Dev

Why is my Ajax not working?

From Dev

Why is TestNG running these test classes multiple times?

From Dev

My bubble sort seems to be running too many times, or running backwards

From Dev

Comparison of running times - similar code runs 4 times slower

From Dev

why does my complete table shown when i enter space more than 4 times in my search script

From Dev

Why is my JQuery running slow?

From Dev

Why is my XAML Code not running?

From Dev

why the app is not running on my cellphone?

From Dev

Why is my basic javascript not running?

From Dev

Why is my Java program not running?

From Dev

Why is my service running as root

From Dev

why the app is not running on my cellphone?

From Dev

Why my celery task is not running?

From Dev

Why is my packer exe not running?

From Dev

Why Ajax post request is executed several times?

From Dev

AJAX request firing 4 times instead of once

From Dev

Why is my program running twice on my Server?

From Dev

Why is my program looping too many times?

From Dev

Why my form showing two times?

From Dev

Why is PyQt executing my actions three times?

From Dev

Why are my jquery script animating at different times?

From Dev

Why Is It That My Object Gets Added 6 Times?

Related Related

HotTag

Archive