jquery的ajax及注意事项
1.引jquery包(jquery-1.8.0.min.js)
<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)); } } }) })
})