在新窗口中输出打印结果

her*_*ron 0 javascript php ajax jquery window

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>
Run Code Online (Sandbox Code Playgroud)

对于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>';
?>
Run Code Online (Sandbox Code Playgroud)

使用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

    });
Run Code Online (Sandbox Code Playgroud)

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

Ric*_*d A 5

你可以尝试:

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
        }
    });
Run Code Online (Sandbox Code Playgroud)