2014-04-25 30 views
0

我見過的加載HTML內容的一些例子,頁面從當前頁面的外像jQuery的負載股利內容到另一頁

$("#divData").load("article.html #target"); 

現在我需要做一些事情完全反之亦然!我的意思是我需要將當前活動頁面的一部分導出到服務器上的現有.php頁面。例如,如果我有一個像

<!DOCTYPE HTML> 
<html> 
<body> 
    <div class="well"> 
    <div class="btn-group"> 
    <button class="btn">Left</button> 
    <button class="btn">Middle</button> 
    <button class="btn">Right</button> 
    </div> 
    <button id="loader" class="btn btn-default">Load To PHP Page</button> 
    </div> 
</body> 
</html> 

的HTML我怎麼可以導出/裝入well內容與它的整個內容到.PHP可以說print.php頁是這樣的:

<?php 

    require_once("dompdf_config.inc.php"); 

    $codigo= '<html> 
       <body> 
       </body> 
       </html>'; 

    $codigo = utf8_decode($codigo); 
    $dompdf = new DOMPDF(); 
    $dompdf->load_html($codigo); 
    ini_set("memory_limit","32M"); 
    $dompdf->render(); 
    $dompdf->stream("ejemplo.pdf"); 

更新:

Data returned from PHP: %PDF-1.3 
1 0 obj 
<< /Type /Catalog 
/Outlines 2 0 R 
/Pages 3 0 R >> 
endobj 
2 0 obj 
<< /Type /Outlines /Count 0 >> 
endobj 
3 0 obj 
<< /Type /Pages 
/Kids [6 0 R 
] 
/Count 1 
/Resources << 
/ProcSet 4 0 R 
/Font << 
/F1 8 0 R 
>> 
>> 
/MediaBox [0.000 0.000 612.000 792.000] 
>> 
endobj 
4 0 obj 
[/PDF /Text ] 
endobj 
5 0 obj 
<< 
/Creator (DOMPDF) 
/CreationDate (D:20140425170443+00'00') 
/ModDate (D:20140425170443+00'00') 
>> 
endobj 
6 0 obj 
<< /Type /Page 
/Parent 3 0 R 
/Contents 7 0 R 
>> 
endobj 
7 0 obj 
<< 
/Length 71 >> 
stream 

0.000 0.000 0.000 rg 
BT 34.016 746.579 Td /F1 12.0 Tf [(salam)] TJ ET 
endstream 
endobj 
8 0 obj 
<< /Type /Font 
/Subtype /Type1 
/Name /F1 
/BaseFont /Times-Roman 
/Encoding /WinAnsiEncoding 
>> 
endobj 
xref 
0 9 
0000000000 65535 f 
0000000008 00000 n 
0000000073 00000 n 
0000000119 00000 n 
0000000273 00000 n 
0000000302 00000 n 
0000000416 00000 n 
0000000479 00000 n 
0000000600 00000 n 
trailer 
<< 
/Size 9 
/Root 1 0 R 
/Info 5 0 R 
>> 
startxref 
710 
%%EOF 

回答

1

如果你想在活動頁面的整個狀態,你可以只提交具有輸入至極包含你想要的HTML表單。如果這是你想要的,你也可以在AJAX中做同樣的事情。

E.g.

HTML

<form action="your_page.php" method="post"> 
    <input type="hidden" name="htmlContent"> 
    <button type="submit">Submit HTML</button> 
</form> 

JS

$('form').submit(function (e) { 
    $(this).children('[name=htmlContent]').val($('.well').html()); 
}); 
0

兩個選項,第一個回答你的問題,你可以使用Ajax發送的div.well的內容print.php

$.ajax({ 
    url: 'print.php', 
    type: 'POST', 
    data: { 
     yourData: $('div.well').html() 
    }, 
    success: function(msg) { 
     alert('Data returned from PHP: ' + msg); 
     // now do something with your returned data, liked load it in a new window. 
    }, 
    error: function (xhr, ajaxOptions, thrownError) { 
     alert('AJAX request failed! ' + xhr.status + ' ' + thrownError); 
    } 
}); 

你可以然後echo $_POST['yourData'];在您的print.php pag e在該頁面上使用div.well

如果加載的內容是靜態的(請參閱下面的註釋),或者您可以將.load("page.html div.well")放在print.php頁面上。

+0

在遠程頁面上使用'load'只有在您不希望保留加載頁面的狀態(假設它是動態的)時纔會起作用。 – plalx

+0

好點,回答更新 – themerlinproject

+0

嗨hemerlinproject謝謝,但我得到的AJAX請求失敗!錯誤在這裏 – Behseini