php
  • javascript
  • jquery
  • ajax
  • window
  • 2012-01-31 3 views 0 likes 
    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에 대해 아래의 PHP 파일에 ajax를 통해 $ _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>'; 
    ?> 
    

    자바 스크립트 :

    $('#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 
         } 
        }); 
    
    관련 문제