Maison > Article > développement back-end > ajax 批量提交
每一行是一条订单 现在给订单加备注 不知道怎么能实现批量提交 求思路
把他当成表单不是一样的吗,和批量删除一样
另外可以在备注文本框加个onchange事件,修改后自动AJAX提交
client.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title> client post</title> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> </head> <body> <script type="text/javascript"> function fsubmit(){ var bzArray = ''; $("input[name='bz[]']").each(function(){ bzArray+= "&bz[" + $(this).attr('oid') + "]="+$(this).val(); }); $.post("server.php", bzArray,function(ret){ alert(ret); }); } </script> <input type="button" value="批量提交" onclick="fsubmit()"> <table> <tr> <td>编号</td> <td>名称</td> <td>价格</td> <td>备注</td> <td>时间</td> </tr> <tr> <td>5121653</td> <td>orer name 1</td> <td>20</td> <td><input type="text" oid="5121653" name="bz[]"></td> <td>1970-01-01 00:00:20</td> </tr> <tr> <td>5121654</td> <td>orer name 2</td> <td>30</td> <td><input type="text" oid="5121654" name="bz[]"></td> <td>1970-01-01 00:00:30</td> </tr> <tr> <td>5121655</td> <td>orer name 3</td> <td>50</td> <td><input type="text" oid="5121655" name="bz[]"></td> <td>1970-01-01 00:00:50</td> </tr> <tr> <td>5121657</td> <td>orer name 4</td> <td>40</td> <td><input type="text" oid="5121657" name="bz[]"></td> <td>1970-01-01 00:00:40</td> </tr> </table> </body></html>
<?php$bz = $_POST['bz'];foreach($bz as $key=>$val){ echo $key.'='.$val."\r\n";}?>
client.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title> client post</title> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> </head> <body> <script type="text/javascript"> function fsubmit(){ var bzArray = ''; $("input[name='bz[]']").each(function(){ bzArray+= "&bz[" + $(this).attr('oid') + "]="+$(this).val(); }); $.post("server.php", bzArray,function(ret){ alert(ret); }); } </script> <input type="button" value="批量提交" onclick="fsubmit()"> <table> <tr> <td>编号</td> <td>名称</td> <td>价格</td> <td>备注</td> <td>时间</td> </tr> <tr> <td>5121653</td> <td>orer name 1</td> <td>20</td> <td><input type="text" oid="5121653" name="bz[]"></td> <td>1970-01-01 00:00:20</td> </tr> <tr> <td>5121654</td> <td>orer name 2</td> <td>30</td> <td><input type="text" oid="5121654" name="bz[]"></td> <td>1970-01-01 00:00:30</td> </tr> <tr> <td>5121655</td> <td>orer name 3</td> <td>50</td> <td><input type="text" oid="5121655" name="bz[]"></td> <td>1970-01-01 00:00:50</td> </tr> <tr> <td>5121657</td> <td>orer name 4</td> <td>40</td> <td><input type="text" oid="5121657" name="bz[]"></td> <td>1970-01-01 00:00:40</td> </tr> </table> </body></html>
<?php$bz = $_POST['bz'];foreach($bz as $key=>$val){ echo $key.'='.$val."\r\n";}?>