Redirect with javascript

Asked

Viewed 806 times

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">&times;</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>

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.