du94414 2016-06-21 16:09
浏览 26

执行查询后打开一个窗口

Im working with Ajax y JQuery to precess my data. What Im try to do is to save data and just when the process is completed sucesfully, it print a ticket in a new window but it just save the data and don´t open anything else.

Here is the code:

<script type="text/javascript">
        $(function(){
            $("#formRenta").on("submit", function(e){
                debugger;
                e.preventDefault();
                var f = $(this);
                var formData = new FormData(document.getElementById("formRenta"));
                $.ajax({
                    url: "/insert/insert_renta.php",
                    type: "post",
                    dataType: "html",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (html) {  
                        var resultado = html.indexOf("Éxito");
                        if (resultado) {
                            document.getElementById("formRenta").reset();
                            new PNotify({
                                title: 'Éxito',
                                text: 'El Contrato de Renta fue creado exitosamente.',
                                type: 'success'
                            });
                            var table = document.getElementById("myTableData");
                            for(i=1; i < 50; i++){
                                table.deleteRow(i);
                            }
                        //SI EL QUERY NO SE EJECUTO EXITOSAMENTE
                        } else {
                            new PNotify({
                                title: 'Error',
                                text: 'Hubo un problema al intentar agregar el Contrato de Renta, intentelo de nuevo.',
                                type: 'error'
                            });
                        }
                    }       
                })
            });
        });
    </script>

So, in insert_renta.php I have something like this:

        [...]
        $rc4 = $stmt4->execute();
        if ( false === $rc4 )
            die('execute() failed: ' . htmlspecialchars($stmt4->error));
        else{
            $idPago = $mysqli->insert_id;
            ?>
                <html lang="es">
                    <body>
                        <div align='center'>
                            <p>Éxito: El pago se realizo correctamente</p>
                        </div>
                        <form id="formRecibo" method="POST" action="/recibo_renta.php" target="_blank">
                            <input type="hidden" name="id_pago" id="id_pago" value="<?php echo $idPago;?>" >
                        </form>
                    </body>
                     <script>
                        $(function(){
                            document.getElementById("formRecibo").submit(); 
                        }
                     </script>
                </html>
            <?php
        }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 相敏解调 matlab
    • ¥15 求lingo代码和思路
    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?