1. 程式人生 > >jquery的ajax及註意事項

jquery的ajax及註意事項

art post name 填充 for this -- lena 班主任

1.引jquery包
<script type="text/javascript">
$(function () {
//根據學院動態填充專業
$("[name=depart]").change(function () {
var did= $(this).val();
if (did==-1){
alert("請選擇學院");
$("[name=major]")[0].length=0;//[0]-->將jquery改為js
$("[name=major]")[0].add(new option("請選擇",-1));//-->動態填充option復選框
} else {
$.ajax({
url: "/Educational/class/getallmajor",
data: "did" + did,
type: "post",
dataType: "json",
success: function (rs) {
$("[name=major]")[0].length=0;
$("[name=major]")[0].add(new option("請選擇",-1));
for (var i = 0; i < rs.length; i++) {
$("[name=major]")[0].add(new Option(rs[i].majorname, rs[i].majorid));
}
}
})
}
})

 //動態確定班主任
$("[name=majorid]").change(function () {
var did= $("[name=deptid]").val();
var mid = $(this).val();
if (mid==-1) {
alert("請選擇專業");
}
$.ajax({
url: "/Educational/class/getrolename",
data: "did" + did+"&mid="+mid,
type: "post",
dataType: "json",
success:function (rs) {
$("[name=classteacher]")[0].length=0;
for (var i = 0; i < rs.length; i++) {
$("[name=classteacher]")[0].add(new Option(rs[i].userName, rs[i].userName));
}
}
})
})




})

jquery的ajax及註意事項