jQuery Ajax.jpg
Jquery Ajax的用法
$.ajax({
//请求方式
type: 'post',
//请求地址
url:"findStudent.action",
//请求数据
data:{
//键值对格式
id:$('#userId').val()
},
//成功时调用的函数
success:function (students) {
//jQuery的遍历集合方法 students表示要遍历的集合,i是下标,student是集合里面的元素
$.each(students,function (i,student) {
var child = "<tr><td>"+ student.studentNo+"</td>"
+"<td>"+student.studentName + "</td>"
+"<td>"+student.sex + "</td>"
+"<td>"+student.gradeId + "</td>"
+"<td>"+student.address + "</td>"+"<tr>"
$('tbody').append(child)
})
},
error:function (){
alert('哈哈')
}
})
jQuery循环的用法
//students 要遍历的集合, i 下标 ,student 每一个对象
$.each(students,function (i,student) {
if (i % 2 === 0) {
color = "<tr style='background-color: rgba(128,128,128,0.2)'><td>";
} else {
color = "<tr><td>";
}
child = color+ student.studentNo + "</td>"
+ "<td>" + student.studentName + "</td>"
+ "<td>" + student.sex + "</td>"
+ "<td>" + student.gradeId + "</td>"
+ "<td>" + student.address + "</td>"
+ "<td> <a href='doEdit.go?id="+student.studentNo +"'>修改</a></td></tr>";
$('tbody').append(child);
})