Posting to a php file via datatables
Posting to a php file via datatables
 elstiv            
            
                Posts: 1Questions: 1Answers: 0
elstiv            
            
                Posts: 1Questions: 1Answers: 0            
            Hi I'm new to datatables but I am finding them very interesting.
I have created this webpage using datatables:
http://www.berlitzmalta.com/ELTONTEST/examples/basic_init/zero_configuration.html
This gathers data via php / mysql. Everything is OK however I am finding it difficult to do the following:
When the user clicks on View Abstract button I need the browser to open a new page or new tab and display the contents of data [5]. This is my code below:
<html>
<head>
    <meta charset="utf-8">
    <link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=2.0">
<title>Department of English Linguistics Theses</title>
<link rel="stylesheet" type="text/css" href="../../media/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="../resources/syntax/shCore.css">
<link rel="stylesheet" type="text/css" href="../resources/demo.css">
<style type="text/css" class="init">
</style>
<script type="text/javascript" language="javascript" src="../../media/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="../../media/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" src="../resources/syntax/shCore.js"></script>
<script type="text/javascript" language="javascript" src="../resources/demo.js"></script>
<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
    var table = $('#example').DataTable( {
    "columnDefs": [ {
        "targets": -1,
        "data": null,
        "defaultContent": "<button>View Abstract</button>"
    } ]
} );
$('#example tbody').on( 'click', 'button', function () {
    var data = table.row( $(this).parents('tr') ).data();
    $.post( "abstract.php", { name: data[5] } );
    window.open ("abstract.php");
    } );
} );
</script>
</head>
        <table id="example" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Author</th>
                    <th>Title</th>
                    <th>Degree</th>
                    <th>Year</th>
                    <th>Abstract</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>ID</th>
                    <th>Author</th>
                    <th>Title</th>
                    <th>Degree</th>
                    <th>Year</th>
                    <th>Abstract</th>
                </tr>
            </tfoot>
            <tbody>
            <?php
$con = mysql_connect('192.168.10.223',"user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("eltontest", $con);
$result = mysql_query( "SELECT * FROM Main");
while($row = mysql_fetch_array($result))
  {
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
  echo "<td>" . $row['AUTHOR'] . "</td>";
  echo "<td>" . $row['TITLE'] . "</td>";
  echo "<td>" . $row['DEGREE'] . "</td>";
  echo "<td>" . $row['YEAR'] . "</td>";
  echo "<td>" . $row['ABSTRACT'] . "</td>";
echo "</tr>";
}
?>
                </tr>
            </tbody>
        </table>
</section>
</body>
</html>
As you can see I am using
$.post( "abstract.php", { name: data[5] } );
        window.open ("abstract.php");
        } );
to post in a php file called abstract.php file the contents of data[5] ... but I am getting a blank page !!
This is the content of my abstract.php file:
<?php
echo $_POST["name"];
<?php > ?>What I want is that when the user clicks on View Abstract button the page submits 'Abstract' to the abstract.php file and displays the information ...
Please help.
Thanks