doujiu7704 2017-12-18 14:53
浏览 57
已采纳

通过AJAX请求生成打印页面上的样式

I use AJAX to simply generator, but i have small problem with styles. I don't find solution of my problem.

I sending request into PHP file with AJAX, this returns HTML code. I getting on javascript and generating "print page". If page doesn't have styles - all is okey, but when i try adding styles with this method, script return white page without content.

$.post({
    type: "POST",
    url: "generate.php",
    data: {pid: pid},
}).done(function(data) {
    output = window.open('');
    output.document.write('<html><head><link rel="stylesheet" type="text/css" href="offer.css" /></head><body>');
    output.document.write(data + '</body></html>');
    output.print();
});

PHP code just like this

<?php
$foo = "foo";
ob_start();
?>

<p><?php echo $foo; ?></p>

<?php 

$result = ob_get_flush();
echo $result;

?>
  • 写回答

1条回答 默认 最新

  • doublel83422 2017-12-18 15:00
    关注

    If write() is used after an HTML document is fully loaded it deletes all existing HTML. So for multiple lines try it like this:

    document.write(
       '<html><head><link rel="stylesheet" type="text/css" href="offer.css" /></head><body>'
       + data + '</body></html>'
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码