克隆全表并提交为表单值

How to correctly copy/clone a html table with javascript and submit it to php, where it will be converted to PDF and XLS documents?

So far I have a html something like this:

<table class="planning-table">
    <thead>
        <tr>
            <td>blah blah</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>blah blah</td>
        </tr>
    </tbody>
</table>

<form id="exportPDFform" method="post">
    <a href="#exportPDF" id="exportPDF">Eksport</a>
    <input id="table_data" type="hidden" name="table" value="" />
</form>

and jquery:

$("#exportPDF").on("click", function (){
    var value = $('.planning-table').clone();
    $("#table_data").val( escape( value ) );
    $("#exportPDFform").submit();
    return false;
});

Now, the cloning works, but, when put inside input field, it gives me:

[object-Object]

How do I correctly do this?

PS: the form gets changed/created dinamically when selecting different filters, so it would be much easier to use the final product then to recreate it on PHP side.

Presumably escape() takes a string whereas you are providing a jQuery object. When you try and cast an object to a string javascript gives you "[object Object]". Instead, you need to retrieve the HTML value of the table, like this:

var value = $('.planning-table').clone().wrap('<div />').parent().html();

I do not think you want to use the Clone() function, instead I think you want to get the HTML content of an element, but using the .html() function on an element above the table.

<div id="table-container">
<table class="planning-table">
    <thead>
        <tr>
            <td>blah blah</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>blah blah</td>
        </tr>
    </tbody>
</table>
</div>

<form id="exportPDFform" method="post">
    <a href="#exportPDF" id="exportPDF">Eksport</a>
    <input id="table_data" type="hidden" name="table" value="" />
</form>

and

$("#exportPDF").on("click", function (){
    var value = $('#table-container').html();
    $("#table_data").val( escape( value ) );
    $("#exportPDFform").submit();
    return false;
});