您的位置:首页 > Web前端 > JavaScript

在jsp的c标签循环后台对象属性的情况下,使用js提取其中一个id属性使用ajax传到后台删除

2018-01-13 11:32 651 查看


jsp代码:

<table>

<tr>
<th>学号</th>

<th>年龄</th>

<th>姓名</th>

<th>班级</th>

<th>性别</th>

<th>操作</th>

</tr>           

<c:forEach items="${sessionScope.load_student}" var="p" >            

 <tbody>              

  <tr>                  

  <td>${p.id}</td>                    

 <td>${p.age}</td>                

    <td>${p.name}</td>                   

<td>${p.classname}</td>               

   <td>${p.sex}</td>               

   <td><input type="button" class="delete"  value="删除" /></td>             

  </tr>            

  </tbody>         

   </c:forEach>

</table>

js代码:

$().ready(function() {

//删除按钮单击处理
$(".delete").click(function(){
       alert(1);
    var tr=$(this).parent().parent();
    var student_id= tr.find("td:first").html();
           //获取请求要提交数据
           alert(student_id);      
 $.ajax({
type:"POST",  
url: "http://localhost:8080/Test/student/delete_student.do",
data:{"student_id":student_id},
dataType:"json",
success: function(result){
                    alert(result);
                    window.location.href=
   "http://localhost:8080/Test/student/load_student.do"; 
   },
   error: function(result){
 
alert(result);
   }
});
});

});    

总结:能够在遍历学生集合中学生对象的属性下,能够使用ajax删除当前行学生。仅供参考,谢谢!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐