日期:2014-05-20  浏览次数:20407 次

大虾帮忙,ajax问题,读xml时出问题了
大虾帮忙,ajax问题,读xml时出问题了,

步骤:1。首先执行SaveChange()函数,修改xml

            2.   读取xml
           
            3.修改页面

<script   language= "javascript ">

var   xmlHttp;
var   requestType   =   " ";

function   createXMLHttpRequest()
{
if   (window.ActiveXObject)  
{
xmlHttp   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
}  
else
if   (window.XMLHttpRequest)
{
xmlHttp   =   new   XMLHttpRequest();
}
}
function   startRequest()
{
createXMLHttpRequest();
xmlHttp.onreadystatechange   =   handleStateChange;
xmlHttp.open( "GET ", "DirectoryXML.xml ",true);
xmlHttp.send(null);
}
function   SaveChange()
{
createXMLHttpRequest();
var   url   =   "DirectoryAjax.aspx?ImageID= "+ <%=ImageID%> + "&Discript= "+document.getElementById( "TxtDescript ").value;
xmlHttp.onreadystatechange   =   handleStateChange;
xmlHttp.open( "GET ",url,true);
xmlHttp.send(null);
}
function   handleStateChange()
{
                if(xmlHttp.readyState   ==4)
{
if(xmlHttp.status   ==   200)
{
listNorthStates();   //接受XML
}
}
}
function   listNorthStates()
{
var   result   =   xmlHttp.responseXML;
var   property   =   null;
var   Discript   =   " ";
var   Imageid   =   null;
var   properties   =   result.getElementsByTagName( "ImageDiscript ");  
alert(properties.length);
////////每次到这里的时候properties.length都提示为零//////////////
for(var   i=0;i <properties.length;i++)
{
proerty   =   properties[i];
Imageid   =   proerty.getAttribute( "ImageID ");
Discript   =   proerty.getElementsByTagName( "ImageDiscript ")[0].firstChild.data;
alert(Imageid+Discript);
if(Imageid   ==   <%=ImageID%> )
{
          document.getElementById( "ImgDiscript ").innerText   =   Discript;
}
                  }
}

</script>
xml为:
<?xml   version= "1.0 "   encoding= "utf-8 "?>
<XmlCenter>
    <Image>
        <ImageDiscript   ImageID= "1402 "> 414141 </ImageDiscript>
        <ImageDiscript   ImageID= "1407 "> 4545 </ImageDiscript>
        <ImageDiscript   ImageID= "1403 "> 4546545454 </ImageDiscript>
    </Image>
</XmlCenter>

------解决方案--------------------
SaveChange()方法中哪有与XML文件有关的调用阿?
------解决方案--------------------
服务器的代码了?
------解决方案--------------------
var url = "DirectoryAjax.aspx?ImageID= "+ <%=ImageID%> + "&Discript= "+document.getElementById( "TxtDescript ").value;