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
});
请帮我在新窗口中发送所有选定的值并输出返回的页面。
答案 0 :(得分: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
}
});