用ajax提交表单,迅速,快捷,实现页面无刷新提交表单。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>ajax批删</title> </head> <body> <center> <table> <tr> <td>姓名</td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td>年龄</td> <td><input type="text" name="age" id="age"></td> </tr> <tr> <td>地址</td> <td><input type="text" name="address" id="address"></td> </tr> <tr> <td></td> <td><button type="button" id="sub">添加</button></td> </tr> </table> </center> </body> </html> <script src="/static/js/jquery.js"></script> <script> $("#sub").click(function(){ var name = $("#name").val(); var age = $("#age").val(); var address = $("#address").val(); $.ajax({ method:"POST", data:{ name:name, age:age, address:address }, url:"{:url(‘Dels/add‘)}" }).done(function(d){ if(d==0){ alert("添加成功"); }else{ alert("添加失败"); } }); }); </script>
原文地址:https://www.cnblogs.com/yingyong/p/9933379.html
时间: 2024-10-31 12:28:21