Stefano,
You can try the code below. What it does is first open the dialog and then sends the AJAX request.
$('#ajax-login-register-login-dialog').dialog('open');
$.ajax({
type: "POST",
url: _ajax_login_settings.ajaxurl,
data: {
action: 'load_template',
referer: 'login_form',
template: 'login-form',
security: $('#ajax-login-register-login-dialog').attr('data-security')
},
success: function( msg ){
$( "#ajax-login-register-login-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
}
});
You can also reference these lines of code in GitHub
https://github.com/zanematthew/zm-ajax-login-register/blob/master/assets/login.js#L95
https://github.com/zanematthew/zm-ajax-login-register/blob/master/assets/login.js#L105