0
I need to redirect when the modal bootstrap loses Focus.
In my code the modal doesn’t open because it redirects off screen. I need something more or less like Alert(). As soon as you click OK or lose Focus I load the right page.
follows 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();
});
Modal opening
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>