AJAX实现二级联动

实战实例:

<pre><code>
//在select上绑定事件监听改变,动态ajax
function getFaculty(centerId){
$.ajax({
type: "get",
url: 'batch/getFacultyByCenterId',
//url: 'batch/save.do',
data: {"CENTER_ID":centerId},
dataType:'json',
cache: false,
error: function(request) {
$('#error_info').removeClass('display-hide');
$('#error_info').html('网络异常,请稍后再试');
},
success: function(data){
var res = eval(data);
//alert(JSON.stringify(res));
   if (res && res.response == "true") {
      //$('#success_info').removeClass('display-hide');
//$('#success_info').html(res.message);
     //location.href="list";
     //alert(JSON.stringify(res.data));
     var fc=res.data;
     var str="";
     for(var i=0;i<fc.length;i++){
     str+="<option value='"+fc[i].FACULTY_ID+"'>"+fc[i].FACULTY_USERTRUENAME+"</option>";
     }
     //alert(str);
     $("#FACULTY_ID").html(str);
    } else {
      $('#error_info').removeClass('display-hide');
$('#error_info').html(res.message);
    }
}
});
}

$("#CENTER_ID").on("change",function(e){
getFaculty($(e.target).val());
});
</code></pre>

推荐阅读更多精彩内容