dtqie02844 2014-06-07 03:59 采纳率: 0%
浏览 66
已采纳

将回应的HTML代码(PHP)附加到Javascript

We have a web application for billing, it gives print from browser. If we give print from browser to dotmatrix printer there will be a speed issue(it pirnts very very slow). So we plan to send raw texts to printer without intervention of browsers print view.

For that i came to know jZebra plugin. It invokes print through java using javascript. By the jzebra tutorial i can append some html and i cant print some text, working fine. like below

<script>
        function print() {
        qz.appendHTML('<html><table style="font-size:10pt; font-face:\'Courier New\';"><tr>' + 
                        '<td colspan="3">Company Name</td>' + 
                        '</tr><tr>' +
                        '<td>TIN: number</td>' + 
                        '<td>ADDRESS<br/>SILK SHOWROOM A/C, PADIYUR</td>' + 
                        '<td>STD: 0000000000/td>' + 
                        '</tr></table></html>');
         // Send characters/raw commands to printer
         qz.printHTML();
    }
</script>

The Problem:

While billing im echoing some HTML like products purchase details and total amounts through PHP on a button click event.

How can i append those HTMLs to the above function?

some of code samples here Calling this PHP through ajax : retail_sales_nontextile_add.php

  try{
        //SELECTING DATA FRO VIEW FROM VI TEMP
        $stmt = $pdo->prepare("SELECT * FROM nontextile_purchase_retailsales_wholesales WHERE bill_number = '$bill_no' ORDER BY id ASC"); $stmt->execute();
        $results            =   $stmt->fetchAll();
     }
     catch(Exception $e){
             print_r($e->getMessage());
             exit;
         }

    foreach($results as $result){
            echo "<tr style='margin-top:-37px;' class='active'><td class='center'></td>";
            echo "<td class='left'>".$result['variety']."</td>";
            echo "<td class='right'>".$result['price']."</td>";
            echo "<td class='center'>".$result['quantity']."</td>";
            echo "<td class='right total'> ".$result['total']."</td>";
            echo "<!--<td class='hidden-print center'><a id='retailsale_nontextile_edit' category ='".$result['category']."' variety='".$result['variety']."' price='".$result['price']."' commision_percent='".$result['commision_percent']."' bill_no='".$result['bill_number']."'>Edit</a></td>-->";
            echo "<td class='hidden-print center'><a id='retailsale_nontextile_delete' id_to_delete='".$result['id']."' bill_no='".$result['bill_number']."'>Delete</a></td></tr>";
                }
                echo "</tbody>
                </table>

with the above echoed HTML how can i append it in the javascript function? AJAX is HERE:

$.post(
             "./php/retailsale/retail_sales_nontextile_add.php",
             { bill_no: bill_no, sale_date: sale_date, category: category, variety: variety, price: price, quantity: quantity, total: total },
             function(data) {
                $('#print_area').html(data);
             }).done(function( data ) {

          });

Thanks for ur help....

  • 写回答

1条回答 默认 最新

  • duanbing8817 2014-06-07 04:30
    关注

    I can think of a few methods you could pass the data to the print. If the two functions are always run together then you can call the post from inside the print or pass the data directly to print:

    function print() {
            $.post(
                 ...
                 }).done(function( data ) {
                     qz.appendHTML('...' + data + '...');
              });
    }
    

    or the opposite method:

    $.post( 
    ...
                     }).done(function( data ) {
                         print(data)
                  });
    

    then use the data in the print function

    function print(data) {
    ...
    }
    

    lastly, if the two functions are independent, you could create a global variable like append outside of the functions.

    var append;
    $.post( 
    ...
                     }).done(function( data ) {
                         append = data;
                  });
    function print() {
       ... + append + ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制