用ajax实现异步刷新,xmlHttp.responseText接到的值不对,求大侠解释
js:
var xmlHttp;
var json;
function createXmlHttpRequest(){
if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest;
}else{
xmlHttpp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function startRequest(path,id){
createXmlHttpRequest();
switch(id){
case 1:
xmlHttp.onreadystatechange = handleStategetClasstype;
break;
case 2:
xmlHttp.onreadystatechange = handleStategetTeacher;
break;
}
xmlHttp.open("get",path);
xmlHttp.send(null);
}
function getClassinfo(url){
startRequest(url+"/teacherAction_findClasstype.action",1);
}
function getTeacher(url){
var id = document.getElementById("check_type").value();
startRequest(url+"teacherAction_findClassteacher.action",2);
}
function handleStategetClasstype(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var root = document.getElementById("check_type");
if(root.options.length==1){
alert(xmlHttp.responseText);
json = eval('('+xmlHttp.responseText+')');
for(i=0;i<json.length;i++){
var option = new Option(json[i].classtypeid,json[i].classtypename);
root.add(option);
}
}
}
}
}
jsp中:
<script type="text/javascript" src="../js/myjs.js"></script>
<script type="text/javascript" src="../js/jquery-1.6.4.js"></script>
<!-- <script type="text/javascript">
$(document).ready(function(){
$.ajax({
url:"/teacherAction_findClasstype.action",
type:"post",
dateType:"json",
success:function(res){
json = eval('('+xmlhttp.responseText+')');
alert(json.length);
for(i=0;i<json.length;i++){
var option = new Option(json[i].classtypeid,json[i].classtypename);
alert(json[i].classtypename);
root.add(option);
}
}
})
}) -->
</script>
</HEAD>
<BODY
onload="getClassinfo('<%=path %>')">
<HR align="center" >
<TABLE width="100%" class="tab_table">
<TBODY>
<TR>
<TD colspan="10" class="no_tab_main_td">
<TABLE class="lower_table" border="0" width="100%">
<TBODY>