【问题标题】:How to print the data returning from $.post()?如何打印从 $.post() 返回的数据?
【发布时间】:2016-10-22 17:36:28
【问题描述】:

我的print 按钮在一页上,数据要打印在另一页上 (print_invoice.php)。如何在 $.post() 中打印返回的数据?谢谢!

$('#print').on('click', function(){
    var id = $('#id').val();
    $.post("print_invoice.php", { ref: id },function(data){
        alert(data);
    });
});

【问题讨论】:

    标签: jquery post printing callback


    【解决方案1】:

    您可以使用打印功能。 如下代码:

    $('#print').on('click', function(){
    var id = $('#id').val();
      $.post("print_invoice.php", { ref: id },function(data){
        printdoc("Print Title","style.css",data);
      });
    });
    function printdoc(wintitle,style,content){
      var mywindow = window.open('',wintitle, 'height=600,width=1000');
      mywindow.document.write('<html><head><title>'+wintitle+'</title>');
      mywindow.document.write('<link href="'+style+'" rel="stylesheet" type="text/css" />');
      mywindow.document.write('</head><body>');
      mywindow.document.write(content);    
    
      mywindow.document.write('</body></html>');
      mywindow.document.close();
      mywindow.print();    
    }
    

    如果数据有完整的设计页面,那么

    function printdoc(wintitle,style,content){
      var mywindow = window.open('',wintitle, 'height=600,width=1000');
      mywindow.document.write(content);    
      mywindow.document.close();
      mywindow.print();    
    }
    

    【讨论】:

    • windows 正在打开,但内容没有写入打印窗口
    • 你能在这里写下 $.post 的回复吗? bcoz 以上我测试的代码及其工作。所以只需要检查你在data中得到了什么
    猜你喜欢
    • 2012-01-03
    • 2022-07-06
    • 1970-01-01
    • 2020-01-29
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多