【问题标题】:Output print result in new window在新窗口中输出打印结果
【发布时间】:2012-01-31 19:59:25
【问题描述】:

HTML:

<form id="dbview" method="post" action="core/process.php">
 ....
<p style='text-align:center;'>
    <input id='delete' type='submit' name='process' value='Delete selected'/>
    <input id='print' type='submit' name='process' value='Print barcodes'/>
</p>
</form>

对于Delete selected,所有工作都执行 process.php 。但是对于Print barcodes,我想通过ajax 将所有选定的复选框值作为$_POST 发送到下面的php 文件。

PHP:

<?php
    echo '<table>';
    for ($i = 1; $i <= 13; $i++) {
        echo '<tr>';
        for ($a = 1; $a <= 5; $a++) {
            echo '<td>';
            foreach ($_POST['checkbox'] as $id) {
                echo '<img src="bc.php?id=' . $id . '"/>';
            }
            echo '</td>';
        }
        echo '</tr>';
    }
    echo '</table>';
?>

Javascript:

 $('#print').click( function(e) { 

        if($('.checkbox:checked').length<1){
            $.notifyBar({
                cls: "error",   
                html: 'At least 1 checkbox must be checked.',
                delay: 5000
            });       
            e.preventDefault();
        }

        //SEND AJAX POST HERE

    });

请帮我发送所有选定的值并在新窗口中输出返回的页面。

【问题讨论】:

    标签: php javascript jquery ajax window


    【解决方案1】:

    你可以试试:

    var checkedValues = $('.checkbox:checked');
    
    $.ajax({
            url: 'print.php',
            type: "POST",
            cache: false,
            data: { checkbox: checkedValues },
            success: function (data) {
                var win = window.open('', 'childWindow', 'location=yes, menubar=yes, toolbar=yes');
                win.document.open();
                win.document.write(data);
                win.print();
                win.document.close();
                win.close(); 
            },
            error: function (e) {
                //Handle Error Here
            }
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      相关资源
      最近更新 更多