关于Ajax响应问题
JSP页面
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'product.jsp' starting page</title>
<script type="text/javascript">
var xmlHttp;
var $ = document.getElementById;
function loadDept(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttp = new XmlHttpRequest();
}
xmlHttp.onreadyStateChange = getDept;
xmlHttp.Open("GET","cate!findCate.action",true);
xmlHttp.setRequestHeader('Content-type',
'application/x-www-form-urlencoded;charset=UTF-8;');
xmlHttp.Send(null);
}
function getDept(){
if(xmlHttp.readyState==4){
if(xmlHttp.Status == 200){
var depts = xmlHttp.responseText;
var js = eval(depts);
var sel = document.getElementById("depts");
for(var i in js){
var Option=document.createElement("OPTION");
Option.value=js[i].categoryId;
Option.text=js[i].categoryName;
sel.options.add(Option);
}
}
}
}
function getDate(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttp = new XmlHttpRequest();
}
var categoryId = document.getElementById("depts").value;
alert(categoryId);
xmlHttp.onreadyStateChange = selectChange;
var url = "cate!findByIdPro.action?categoryId="+categoryId;
alert(url);
xmlHttp.Open("GET",url,true);
xmlHttp.Send(null);
}
function selectChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status ==200){
var datas=xmlhttp.responseText;
var jes=eval(datas);
alert("+++"+dates);
var tbs=document.getElementById("tbs");
for(var i=tbs.rows.length-1;i>=0;i--)
{
tbs.deleteRow(i);
}
for( var w in jes)
{
var newRow=tbs.insertRow(tbs.rows.length);
newRow.insertCell(0).innerHTML=jes.productId;
newRow.insertCell(1).innerHTML=jes.productName;
newRow.insertCell(2).innerHTML=jes.price;
newRow.insertCell(3).innerHTML=jes.createDate;
newRow.insertCell(4).innerHTML="<a href='javascript:del("+jes[w].productId+")'>删除</a>";
}
}
}
}
function del(productId)
{
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttp = new XmlHttpRequest();
}
xmlhttp.onreadyStateChange=selectChange;
var url = "cate!findByIdPro.action?categoryId="+productId;
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader('Content-type',
'application/x-www-form-urlencoded;charset=UTF-8;');
xmlhttp.send(null);
}
</script>
</head>
<body>
<form>
<input type="button" value="加载部门" onclick="loadDept()"/>
&nb