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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料