日期:2014-05-19  浏览次数:20400 次

关于Ajax无法得到返回的xml.请大家看看
关于Ajax无法得到返回的xml.请大家看看
返回一个xml.可是在前台无法得到。
顺便问一下。我没有用ajax.dll,没有影响吧?

var   xmlHttp;
var   requestType   =   " ";

function   createXMLHttpRequest()//创建对象
{
if   (window.ActiveXObject)  
{
xmlHttp   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
//xmldoc       =       new       ActiveXObject( "Msxml2.DOMDocument ");      
}  
else
if   (window.XMLHttpRequest)
{
xmlHttp   =   new   XMLHttpRequest();
}
}

function   SaveChange()//点击保存按钮首先执行这个
{
createXMLHttpRequest();
var   url   =   "DirectoryAjax.aspx?ImageID=1&Discript=1111+ "&   rand= "+Math.random();

xmlHttp.open( "GET ",url,true);
xmlHttp.onreadystatechange   =   handleStateChange;
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   Imageid   =   null;
var   properties   =   result.getElementsByTagName( "ImageDiscript ");  
alert(properties.length+result);

                  //   ********每次在这里properties.length的长度都为0。不知为什么?***********

for(var   i=0;i <properties.length;i++)
{
proerty   =   properties[i];
Imageid   =   proerty.getAttribute( "ImageID ");
alert(proerty.childNodes(0).nodeValue);
}
}

cs   代码:
using   System;
using   System.Collections;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.SessionState;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;
using   System.IO;


namespace   EShop.UserCenter
{
///   <summary>
///   DirectoryAjax   的摘要说明。
///   </summary>
public   class   DirectoryAjax   :   System.Web.UI.Page
{
//private   XmlDocument   xmlDoc;
private   int   ImageId;
private   string   Discripts;
private   void   Page_Load(object   sender,   System.EventArgs   e)
{
      int   ImageId   =   Convert.ToInt32(Request.QueryString[ "ImageID "]);
                                          string   Discripts   =   Request.QueryString[ "Discript "];

                                          Response.ContentType   =   "text/xml ";
                                          Response.CacheControl= "no-cache ";
                                          string   XmlStr   =   " <response> <Image> ";