After php query open result on a new page

Asked

Viewed 204 times

1

How can I, if you have how, open a new page after returning a query on php, what I have today is this here:

$(function () {
$("#frmConsulta").validate({
    submitHandler: function (form) {

        var data = $(form).serialize();
        console.log(data);  

        $.ajax({
            type: 'POST',
            url: 'ajax/pRelatorioEvolucaoSafra.php',
            data: data,
            dataType: 'html',

            success: function (response) {

                // EXIBINDO O RETORNO DAS INFORMAÇÕES   
                $("#msgRelatorio").html(response);

                $('#frmConsulta').each(function () {
                    this.reset();
                });
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(xhr, ajaxOptions, thrownError);
                $("#msgRelatorio").html('<div class="alert alert-danger fade in"><button class="close" data-dismiss="alert">×</button><i class="fa-fw fa fa-times"></i><strong>ATENÇÃO!</strong> Ocorreu um erro ao tentar efetuar a consulta. Contate o suporte técnico.</div>');
            }
        });
        return false;
    }
});

});

In return I am positioned a table in the div msgRelatorio, but I need to open it on a new page.

  • 2

    If you want to switch pages, why make an asynchronous request and not synchronous?

  • 1

    Save the data in LocalStorage and then search them on another page via javascript. If this is a valid option I can post a reply.

1 answer

1


As commented by Anderson Carlos Woss. The correct thing to do is an asynchronous request. But anyway, you can do it using the LocalStorage:

success: function (response) {
    localStorage.setItem('nome_salvo', JSON.stringify(response));
    // JSON.stringify para transformar os dados em formato JSON
}

And on the other page just take the data:

var consulta = JSON.parse(localStorage.getItem('nome_salvo'));
//JSON.parse transforma dos dados em JSON para Objetos
// Dessa forma você pode acessar os dados assim: consulta.nome

After collecting the data, delete them:

localStorage.removeItem('nome_salvo');
  • 1

    Hello Djalma Manfrin, yes I understood what was commented, only then calmly I resolved as indicated, but I appreciate the help, this code helped me in another issue.

Browser other questions tagged

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