双重促动模糊事件

I have javascript code, which should be executed once at focus shift. Everything works, but this code is carried out two times for some strange reason, thus I give TWO alert windows.

$(document).ready(function() {
    $('#username').blur(function() {

        var formData = {
            "username":$('#username').val()
        };

        $.ajax({
            url:'check.php',
            type:'POST',
            data:'jsonData=' + $.toJSON(formData),
            success: function(res) {
                alert(res);
            }

        });
    });
});

What am I doing wrong?

Some browsers (Chrome, maybe Safari) fire a separate "blur" event when the browser window loses focus. It seems like a bug to me, and I don't know what can be done about it.

To elaborate: if you've got a "blur" handler on an <input>, and it's got focus, and then you click outside the browser window (or ALT-TAB to another application), then Chrome fires two "blur" events. Both events will look pretty much the same, so it's hard to tell whether you should pay attention or not.

The best suggestion I have is to toggle some "class" value or something on "focus" and "blur", and ignore a "blur" that doesn't look to be in the proper "I was just focused" state.

Here's the question I posted on that issue.

I moved this code before #username div and everything have worked as it should.