2016-10-22 3 views
0

私は自分のprintボタンを1ページに、データを別のページ(print_invoice.php)に印刷しました。返されたデータを$ .post()に出力するにはどうすればよいですか?ありがとうございました!

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

答えて

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();  
} 
+0

ウィンドウをフルデザインのページを持っている場合は、開いているが、内容はあなたがここに$ .postの応答を書くことができ、印刷ウィンドウ – Naresh

+0

への書き込みをされていません。私がテストしたコードの上にbcozとその動作。それで、あなたが 'データ 'に入っているものを確認するだけでいいです – Veer

関連する問題