I want to use a dialog confirm of jquery ui that is added by pressing a "save" button, that if "yes" is pressed then that a $ .ajax method is executed that saves the information in the bd. This is what I have:
$('#btnGuardaInforme').on('click',function(e){
var comentarios = $('#comentarios').val();
var plan = $('#plan').val();
var periodo = $('#txtperiodo').val();
var idIndicador = $('input#textIdindicador').val();
var resultado = $('#txtresultado').val();
e.preventDefault();
$('#dialog-confirm').dialog("open");
});
$( function () { //DIALOG CONFIRM
$( "#dialog-confirm" ).dialog({
resizable: false,
autoOpen: false,
height: "auto",
width: 400,
modal: true,
buttons: {
"Guardar": function() {
$.ajax({
type: 'post',
url: baseUrl + 'Informe/GuardaInforme',
data: {idIndicador: idIndicador, periodo: periodo, comentarios: comentarios, plan: plan,resultado: resultado},
success: function(){
console.log('Guardado ok');
},
error: function(){
console.log('error ajax al guardar informe');
}
});
console.log('ok confirm');
$( this ).dialog( "close" );
},
Cancelar: function() {
$( this ).dialog( "close" );
}
}
});
});
The function of the dialog I have outside the click event of the button and I do not know how to pass the variables sent by ajax.