open page with window.open and send variable

1

I have a problem, when sending and registering in the bd a sale sends me a confirmation message and that I show on the screen:

This code captures the submit and receives the message:

$(".frm-ventas").submit(function(event) {
        event.preventDefault();
        var url = $(this).attr('action');
        var data = $(this).serialize();
        $.ajax({
            type:'POST',
            dataType:'json',
            url:url,
            data:data,
            success:function(response){
                $('#caja').toggle();
                $("span").remove( ".mensaje" );
                $("i").remove('.glyphicon');
                $("#caja").fadeOut(5000);

                if (response.respuesta == true) {
                    $(".box-pago").hide();
                   setTimeout(function(){ 
                   window.open("example/report/factura.php?invoice=reponse.invoice");
                   }, 5000); // 5000 ms                  
                    $('#caja').removeClass('alert-danger').addClass('alert-info');
                    $("#caja").append("<i class='glyphicon glyphicon-info-sign' aria-hidden='true'></i>");
                    $("#caja").append("<span class='mensaje'>"+" ok: "+response.mensaje+"</span>");
                    $('.cargando').toggle();
                    $('.cargando p').html('Limpiando el carrito...');
                    setTimeout(llenar_tabla_json, 2000);
                    limpiarformulario($(".frm-ventas"));

                }else{
                    $('#caja').removeClass('alert-info').addClass('alert-danger');
                    $("#caja").append("<i class='glyphicon glyphicon-exclamation-sign' aria-hidden='true'></i>");
                    $("#caja").append("<span class='mensaje'>"+" Error: "+response.mensaje+"</span>");
                }
            },error:function(){
                alert("Ha ocurrido un error");
            }
        });
    });

And this is the message:

$salidaJson=array('respuesta' => $mensajeOk,'mensaje' => $mensajeError, 'invoice' => $invoice);
            echo json_encode($salidaJson);

I want to open that page with window.open and send the variable $invoice try with this code and nothing

window.open("example/report/factura.php?invoice=reponse.invoice");

Any ideas?

this is the 'variable' $ invoice that I want to send

$ client = new Client ();

                       $client->setTipoDoc('6')
                              ->setNumDoc(trim($_POST['ruc']))
                              ->setRznSocial(trim($_POST['cliente']))
                              ->setAddress((new Address())
                              ->setDireccion(trim($_POST['direccion'])));
                              // Emisor
                       $address = new Address();
                       $address->setUbigueo($ubigeo)
                              ->setDepartamento($departamento)
                              ->setProvincia($provincia)
                              ->setDistrito($distrito)
                              ->setUrbanizacion($urbanizacion)
                              ->setDireccion($direccionempresa);

                       $company = new Company();
                       $company->setRuc($rucempresa)
                              ->setRazonSocial($razonempresa)
                              ->setNombreComercial($nombre_comercial)
                              ->setAddress($address);
                              // Venta

                       $invoice = new Invoice();
                       $invoice
                              ->setFecVencimiento(new DateTime())
                              ->setTipoDoc($tipo_documento)
                              ->setSerie(trim($_POST['serie']))
                              ->setCorrelativo(trim($_POST['numero']))
                              ->setFechaEmision(new DateTime())
                              ->setTipoMoneda(trim($_POST['pago']))
                              ->setClient($client)
                              ->setMtoOperGravadas($gravadas)                                
                              ->setMtoIGV($importeIGV)
                              ->setMtoImpVenta($importe)
                              ->setCompany($company);
                               $leyenda = trim($_POST['total']);
                       $centimos = substr($leyenda, -2);
                       $legn = validar::convertir($leyenda,'CON '.$centimos.'/100 SOLES');                          
                       $legend = new Legend();
                       $legend->setCode('1000')
                              ->setValue($legn);

                       $invoice->setDetails($items)
                              ->setLegends([$legend]);
    
asked by Fernando Abel Gonzales Ch 14.02.2018 в 17:26
source

1 answer

1

If you already get the value of ajax correctly that is to say in the object response you will have the properties (response.response, response.message, response.invoice) . To send to window.open the value of invoice you only need to concatenate that value (response.invoice) to the first parameter of window.open ie send by GET to factura.php for then in factura.php can access by means $_GET['invoice']

if (response.respuesta == true) {
  $(".box-pago").hide();
  setTimeout(function(){ 
     window.open("example/report/factura.php?invoice="+response.invoice , '_blank');
 }, 5000); // 5000 ms

From factura.php

echo $_GET['invoice'];

Update

If the object obtained by Ajax is a array , it must convert to a valid format to send by get which is achieved with $.param .

  let invo = $.param(response.invoice);
  setTimeout(function(){ 
     window.open("database.php?invoice=&"+invo , '_blank');
 }, 5000); // 5000 ms

From PHP you would access the properties directly from invoice . for example if you have a client field.

echo $_GET['cliente']; 
    
answered by 14.02.2018 в 17:36