
jQuery Ajax.jpg
Jquery Ajax的用法
$.ajax({
//請(qǐng)求方式
type: 'post',
//請(qǐng)求地址
url:"findStudent.action",
//請(qǐng)求數(shù)據(jù)
data:{
//鍵值對(duì)格式
id:$('#userId').val()
},
//成功時(shí)調(diào)用的函數(shù)
success:function (students) {
//jQuery的遍歷集合方法 students表示要遍歷的集合,i是下標(biāo),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循環(huán)的用法
//students 要遍歷的集合, i 下標(biāo) ,student 每一個(gè)對(duì)象
$.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);
})