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 + ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥20 win11无法启动 持续蓝屏且系统还原失败,无法开启系统保护
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码