jquery php ajax刷新的问题???
<?phpecho'<tablewidth="90%"id="mytab"border="1"class="t1">';echo'<thead>';echo'<tr>';...
<?php
echo '<table width="90%" id="mytab" border="1" class="t1">';
echo '<thead>';
echo '<tr > ';
echo ' <th width="30px">编号</th>';
echo ' <th width="55px">名字</th>';
echo '<th width="60px">发布时间</th> ';
echo ' <th width="50px">手机单</th> ';
echo '<th width="50px">双链接</th> ';
echo '<th width="30px">远程</th> ';
echo ' <th width="30px">砖号</th>';
echo ' <th width="55px">IP</th>';
echo ' <th width="30px">点数</th>';
echo ' <th width="230px">任务要求</th>';
echo ' <th width="30px">金额</th>';
echo ' <th width="30px">发布</th> ';
echo ' <th width="30px">被接</th>';
echo ' <th width="50px">操作</th>';
echo ' </tr>';
echo ' </thead>';
$conn=mysql_connect("127.0.0.1","root","");
mysql_query("set names utf8",$conn) or die(mysql_errno());
mysql_select_db("ba",$conn) or die(mysql_errno());
$sql="select * from renwu";
echo "<div id=xianshi>";
while($a=mysql_fetch_assoc($ab)){
echo " <tr> ";
echo "<td>{$a['bianhao']} </td> ";
echo " <td>{$a['mingzhi']}</td>";
echo " <td>{$a['ruqi']}</td> ";
echo " <td>{$a['shoujidan']}</td> ";
echo " <td>{$a['shuanglianjie']}</td>";
echo " <td>{$a['yuancheng']}</td> ";
echo " <td>{$a['zhuanghao']}</td> ";
echo " <td>{$a['ip']}</td>";
echo " <td>{$a['dianshu']}</td> ";
echo " <td>{$a['renwu']}</td>";
echo " <td>{$a['jinge']}</td>";
echo " <td>{$a['fabu']}</td>";
echo " <td>{$a['beijiie']}</td>";
echo " <td><input id={$a['bianhao']} type='button' value='抢任务'></input></input><input type='hidden' value='12'></td>";
echo " </tr>";
}
echo "</div>";
echo " </table>";
?>
php代码是上面的,
上图是运行的结果,当点抢任务的时候,通过ajax把数据提交,
js我就不放上面了,还是ajax和后台交互我也会的,我现在的问题就是前台是用循环打出来的表格,我现在的想法通过AJAX修改数据库,而修改数据库的那一条记录就不输出,然后通过后台输出一份表格,问题就是怎么替换已经在前台的表格,用什么方法, 展开
echo '<table width="90%" id="mytab" border="1" class="t1">';
echo '<thead>';
echo '<tr > ';
echo ' <th width="30px">编号</th>';
echo ' <th width="55px">名字</th>';
echo '<th width="60px">发布时间</th> ';
echo ' <th width="50px">手机单</th> ';
echo '<th width="50px">双链接</th> ';
echo '<th width="30px">远程</th> ';
echo ' <th width="30px">砖号</th>';
echo ' <th width="55px">IP</th>';
echo ' <th width="30px">点数</th>';
echo ' <th width="230px">任务要求</th>';
echo ' <th width="30px">金额</th>';
echo ' <th width="30px">发布</th> ';
echo ' <th width="30px">被接</th>';
echo ' <th width="50px">操作</th>';
echo ' </tr>';
echo ' </thead>';
$conn=mysql_connect("127.0.0.1","root","");
mysql_query("set names utf8",$conn) or die(mysql_errno());
mysql_select_db("ba",$conn) or die(mysql_errno());
$sql="select * from renwu";
echo "<div id=xianshi>";
while($a=mysql_fetch_assoc($ab)){
echo " <tr> ";
echo "<td>{$a['bianhao']} </td> ";
echo " <td>{$a['mingzhi']}</td>";
echo " <td>{$a['ruqi']}</td> ";
echo " <td>{$a['shoujidan']}</td> ";
echo " <td>{$a['shuanglianjie']}</td>";
echo " <td>{$a['yuancheng']}</td> ";
echo " <td>{$a['zhuanghao']}</td> ";
echo " <td>{$a['ip']}</td>";
echo " <td>{$a['dianshu']}</td> ";
echo " <td>{$a['renwu']}</td>";
echo " <td>{$a['jinge']}</td>";
echo " <td>{$a['fabu']}</td>";
echo " <td>{$a['beijiie']}</td>";
echo " <td><input id={$a['bianhao']} type='button' value='抢任务'></input></input><input type='hidden' value='12'></td>";
echo " </tr>";
}
echo "</div>";
echo " </table>";
?>
php代码是上面的,
上图是运行的结果,当点抢任务的时候,通过ajax把数据提交,
js我就不放上面了,还是ajax和后台交互我也会的,我现在的问题就是前台是用循环打出来的表格,我现在的想法通过AJAX修改数据库,而修改数据库的那一条记录就不输出,然后通过后台输出一份表格,问题就是怎么替换已经在前台的表格,用什么方法, 展开
1个回答
展开全部
你好,使用jquery直接将table中的内容重新设置, $("#mytab").html(newtab); 这个newtab你必须把html给拼接好,
如果newtab纯内容的话,也就是<tr></tr>之类的,$("#mytab").html($("#mytab tr:first")+newtab);留下表头然后加上内容,
或者直接删除当前的table,在添加一个新的table
$("#mytab").remove();
$(newtab).appendTo("body");//添加新的表格到body中
你什么问题可以追问我
希望可以帮助到你
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询