大家帮我看看下面的代码哪里除了问题?个人觉得可能是LoadClassXml.aspx有问题,因为我把 <body onload= "talktoServer( '../Action/LoadClassXml.aspx ', '-1 ');改成
<body onload= "talktoServer( '../1.xml ', '-1 ');是可以正常工作的。
=====================================================
<script language= "javascript " type= "text/javascript ">
var req;
var sel1;
function talktoServer(url,s1){
sel1 = s1;
req = newXMLHTTPRequest();
var callbackHandler = getReadyStateHandler;//注册客户端回调函数
req.onreadystatechange = callbackHandler;
req.open( "POST ",url,true);
req.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");
//对url进行编码
req.send(null);
}
//创建一个xmlhttprequest对象
function newXMLHTTPRequest(){
var xmlreq = false; //定义一个xmlhttprequest变量,初始值为false
if(window.XMLHTTPRequest) {
xmlreq = new XMLHTTPRequest(); //如果支持XMLHTTPRequest,则创建
} else if(window.ActiveXObject) {
try {
xmlreq = new ActiveXObject( "Msxml2.XMLHTTP "); //IE高版本中创建XMLHTTP对象
} catch (e1) { //创建第一个XMlHTTP失败
try {
xmlreq = new ActiveObject( "Microsoft.XMLHTTP "); //IE低版本中创建XMLHTTP
} catch (e2) {
}
}
}
return xmlreq;
}
//服务器回调函数
function getReadyStateHandler(){
if(req.readyState ==4) { //已经加载
if(req.status == 200) { //返回成功
var obj = document.getElementById( "class1 ");
var obj2 = document.getElementById( "class2 ");
var xmlDoc = req.responseXML;
var node = xmlDoc.documentElement; //alert(node);node为空
alert(node);
if(sel1!= "-1 ")
{
obj2.options.length = 0;
obj2.add(new Option( "二级分类 ", "-1 "));
}
for(var i=0;i <=node.childNodes.length-1;i++)
{
//添加一个选项
if(node.childNodes(i).childNodes(2).text== "0 " && sel1== "-1 ")
{
obj.add(new Option(node.childNodes(i).childNodes(1).text,node.childNodes(i).childNodes(0).text));
}
if(sel1==node.childNodes(i).childNodes(2).text)
{
obj2.add(new Option(node.childNodes(i).childNodes(1).text,node.childNodes(i).childNodes(0).text));
}
}
}
}
}
</script>
<body onload= "talktoServer( '../Action/LoadClassXml.aspx ', '-1 ');