2012-01-31 13 views
0

HTML:すべての作業がprocess.phpを行い出力印刷結果

<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について。しかし、Print barcodesのために、以下のajaxからphpファイルまで、すべての選択されたチェックボックスの値を$ _POSTとして送信したいと思います。

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 

    }); 

私は新しいウィンドウで選択したすべての値と出力返されたページを送信するために助けてください。

答えて

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 
     } 
    }); 
関連する問題