I need to redirect when the modal bootstrap loses focus.
In my code the modal does not even open because it does the redirection coming out of the screen. I need something more or less like the alert (). As soon as I click on ok or lose focus I load the right page.
Follow my code.
jQuery.ajax({
type: 'POST',
mimeType: "multipart/form-data",
url: 'model/acao/controller.php',
dataType: 'json',
data: formData,
contentType: false,
processData: false
}).done(function (html) {
// var res = JSON.parse(html);
if (html.hasOwnProperty("erro")) {
if (acao === 'Incluir') {
modal("Erro ao salvar");
}
if (acao === 'Alterar') {
modal("Erro ao alterar");
}
} else {
if (html.success === "ok") {
if (acao == 'Incluir') {
modal("Salvo com sucesso");
}
if (acao == 'Alterar') {
modal("Alterado com Sucesso");
}
//redirecionando a pagina
location.href = "?index.php&pagina=" + getUrlVars()['pagina'] + "&acao=listar";
} else {
alert(html);
}
}
}).fail(function (jqXHR, textStatus, errorThrown) {
alert("Erro ao inserir. " + errorThrown);
}).complete(function () {
Self.working = false;
$("#load").hide();
});
Opening modal
function modal(msg) {
$('.modal-body').html(msg);
$('#myModal').modal('show');
}
html
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Informação</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">OK</button>
</div>
</div>
</div>
</div>