I think i have not understood correctly var scalabality. Can you explain me this :
i have a function like that :
function myFunction () {
    var test = $(this).data('type');
    console.log("start :"+test);
    $.ajax({
        url: 'myUrl',
        type: 'POST',
        contentType: false,
        processData: false,
        dataType: 'json',
        data: data,
        success: function (response) {
            console.log("end :"+test);
        }
    });
}
This function is called when i click on a button :
$('.js-button').on('click', myFunction);
when i submit my form, i have to trigger the click on all visible buttons so i do :
$('.submit').click(function(){
    $('.button').each(function(){
        if ($(this).is(":visible")){
            $(this).trigger("click");
        }
    });
    return false;
});
in my function, "$(this).data('type')" gets the data-type atribute of the button
If i have 2 visible buttons with data-type="toto" and data-type="titi", i have this log :
start :toto
start :titi
end :titi
end :titi
Why do i have "titi" two times in the ajax callback i thougt "var test" was not global, am i wrong
thanks for your help
EDIT : here is a jsFiddle if "test" is declared without "var", you can reproduce if you write "var test = = $(this).data('type');" it works correctly
