Aan Aan - 1 year ago 74
PHP Question

Display HTML code from $_POST variable

I am trying to send html code using post by the following JavaScript code:

var htmlTable= $('#granting_result').html();
$('<form action="tbl_create.php" method="POST"><input type="hidden" name="data" value='+htmlTable+' ></form>').submit();

The receiving page
has the following php code:


echo $_POST['data'];


The problem is that this page is shown as a blank page and nothing displayed, although the output of
is as following:
enter image description here

Answer Source

Create the form elements themselves and pass the html string as value property of the input instead of concatenating as attribute.

Then insert into dom and submit

var $input = $('<input>',{type:'hidden', name:'data'}).val(htmlTable);
var $form = $('<form>',{method:'post', action:'tbl_create.php'});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download