AJAX - 打印页面内容 [英] AJAX - Print Page Content

查看:126
本文介绍了AJAX - 打印页面内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AJAX来发送表单数据到建立并发送HTML邮件服务器的PHP文件。这个数据我回荡在服务器上的PHP文件的一部分。这是呼应的HTML生成一个,我想用户打印(在纸上)表。我想打开默认浏览器的打印对话框,以便用户可以打印的表,他/她看不到。我不在乎,如果一个新的选项卡,打开显示呼应的内容。这甚至可能?

I am using AJAX to send form data to a server php file that builds and sends an html email. A portion of this data I am echoing on the server php file. The html that is echoed builds a table that I would like the user to print (on paper). I'd like to open the default browser print dialog so the user can print the table that he/she cannot see. I don't care if a new tab has to open displaying the echoed content. Is this even possible?

推荐答案

返回HTML表单Ajax请求,然后使用JavaScript来打印

return that html form ajax request and then use javascript to print


这code未经测试


This code is not tested

JQuery的/ Javascript的

$.post("EmailFile.php", { "EmailParam": "EmailVal" },
     function(data){
         var HTML = data.EmailHTML;

        var WindowObject = window.open("", "PrintWindow", "width=750,height=650,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes");
        WindowObject.document.writeln(HTML);
        WindowObject.document.close();
        WindowObject.focus();
        WindowObject.print();
        WindowObject.close();

     }, "json");



的PHP文件(EmailFile.php)



PHP File (EmailFile.php)

$EmailData = $_POST['EmailParam'];
//...Send Email...

//..Build HTML...
$TableHTML = "<table></table>";

//Return HTML
$JSONArr['EmailHTML'] = $TableHTML;
echo json_encode($JSONArr);

这篇关于AJAX - 打印页面内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆