|
关于xml.sendAndLoad的问题(发送信息到服务器后无法收到返回数据)
各位高手好! 小弟第一次写AS,遇到一个奇怪的问题:
我试图通过FLASH发送一条查询数据到同域下的一个ASP.NET文件,并接收查询结果,但是发送是成功了,却始终收不到返回结果,不知是怎么回事?下面是我的代码片断:
loginXML = new XML(); var loginElement:XMLNode; loginElement = loginXML.createTextNode(totalFileSize.toString()); loginXML.appendChild(loginElement); //新建一个xml对象,用来存放从服务器返回的信息 loginReplyXML = new XML(); loginReplyXML.ignoreWhite=true; loginReplyXML.onLoad=upload; loginXML.sendAndLoad("getCheckInfo.aspx?type=maxsize",loginReplyXML);
public function upload(success:Boolean){ if (success){ onError("sss"); /*var reply = loginReplyXML.firstChild; if (reply.nodeName == "RESULT"){ switch(reply.attributes.value) { case "1": dispatchEvent ({type:"start"}); uploadNext (); break; case "0": onError(reply.attributes.errorMessage); break; default: onError("服务器发生未知错误,上传失败!请重试!"); break; } }*/ } else{ onError("服务器发生未知错误,上传失败!请重试!"); }
***onError是我自定义的一个输出错误信息的方法。是确定可以正确执行的!
getCheckInfo.aspx
private void GetMaxSize() { int maxSize=10240; int totalSize=0; System.Xml.XmlDocument xml=new System.Xml.XmlDocument(); if (Request.Form.Count>0) { try { totalSize=int.Parse(Request.Form[0]); } catch { xml=new System.Xml.XmlDocument(); System.Xml.XmlElement xmlE=xml.CreateElement("RESULT"); xmlE.SetAttribute("value","0"); xmlE.SetAttribute("errorMessage","请求的数据无效!"); xml.AppendChild(xmlE); } if (totalSize>maxSize) { xml=new System.Xml.XmlDocument(); System.Xml.XmlElement xmlE=xml.CreateElement("RESULT"); xmlE.SetAttribute("value","0"); xmlE.SetAttribute("errorMessage","可用空间大小不足!"); xml.AppendChild(xmlE); } else { xml=new System.Xml.XmlDocument(); System.Xml.XmlElement xmlE=xml.CreateElement("RESULT"); xmlE.SetAttribute("value","1"); xml.AppendChild(xmlE); } } else { xml=new System.Xml.XmlDocument(); System.Xml.XmlElement xmlE=xml.CreateElement("RESULT"); xmlE.SetAttribute("value","0"); xmlE.SetAttribute("errorMessage","数据无效!"); xml.AppendChild(xmlE); } //System.Xml.XmlTextWriter xmlW=new System.Xml.XmlTextWriter(Response.OutputStream,System.Text.Encoding.Default); //xmlW.WriteStartDocument(); //xml.WriteTo(xmlW); //xmlW.WriteEndDocument(); //xmlW.Close(); Response.Clear(); Response.ContentType="text/xml"; Response.Write(xml.OuterXml); Response.End(); }
调用xml.send方法后得到如下输出内容:
<RESULT value="0" errorMessage="数据无效!" />
我在getCheckInfo.aspx中返回一串XML格式的代码,用xml.send测试通过了的。而且我在ASPX文件中的相关代码中建立了一个新文件(用来判断是否成功接收到了FLASH的数据),在我执行了xml.sendAndLoad之后,文件建立起了,说明ASPX文件是接收到了FLASH传来的数据的。可是FLASH端的loginReplyXML.onLoad却始终没有被执行。不知道是为什么?望高手指教!!!
|