【发布时间】:2014-07-14 06:18:40
【问题描述】:
您好,我是数据表的新手,但我发现它们非常有趣。
我使用数据表创建了这个网页:
http://www.berlitzmalta.com/ELTONTEST/examples/basic_init/zero_configuration.html
这通过 php / mysql 收集数据。一切都很好,但是我发现很难做到以下几点:
当用户单击查看摘要按钮时,我需要浏览器打开一个新页面或新选项卡并显示数据内容 [5]。这是我下面的代码:
<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( { //"ajax": "data/arrays.txt", "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","passxxxx");
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>
如你所见,我正在使用
$.post( "abstract.php", { name: data[5] } ); window.open ("abstract.php"); } );
在一个名为 abstract.php 的 php 文件中发布 data[5] 的内容 ...但我得到一个空白页!!
这只是(目前)我的 abstract.php 文件的内容:
<?php echo $_POST["name"]; ?>
我想要的是,当用户点击查看摘要按钮时,页面将“摘要”提交到 abstract.php 文件并显示信息...
请帮忙。
谢谢
【问题讨论】:
标签: php jquery mysql datatable datatables