µ±Ç°Î»Ö㺠´úÂëÃÔ >> Ajax >> ΪʲôȡxmlHttp.responseXML.documentElementȡΪ¿Õ?
  Ïêϸ½â¾ö·½°¸

ΪʲôȡxmlHttp.responseXML.documentElementȡΪ¿Õ?

Èȶȣº791   ·¢²¼Ê±¼ä£º2012-02-10 21:27:42.0
ΪʲôȡxmlHttp.responseXML.documentElementȡΪ¿Õ? - Web ¿ª·¢ / Ajax
ÒªÇó,ÔÚaspÒ³ÃæÖÐÊäÈ빤ºÅÏîÖÐÊäÈ빤ºÅ,×Ô¶¯ÔÚ¸ÃÒ³ÃæÖÐÏÔʾ¸Ã¹¤ºÅµÄÏà¹ØÊý¾Ý,±ÈÈç¶ÔÓ¦µÄÐÕÃû,µç»°µÈ.

Ïëµ½ÓÃAjax ʵÏÖ,´úÂëÈçÏÂ:

a.aspÒ³Ãæ,¸Ã²¿·ÖHTML´úÂëÊ¡ÂÔ.
VBScript code

.....
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="course_style.css" rel="stylesheet" type="text/css">
<script src="showpersonalinfo.js"></script>
....
<form name="form" method="post" action="sendproc.asp" onSubmit="return chkform();">
...
<td ><input type="text" name="worknum" id="worknum" onKeyUp="showpersonalinfo(this.value)"><td>
<td><input type="text" name="name" id="name"></td>
<td><input name="extension" type="text" id="extension"></td>
....
</form>




showpersonalinfo.jsÒ³Ãæ
JScript code

var xmlHttp;

function showpersonalinfo(str)
{
    xmlHttp=GetXmlHttpObject();
    if(xmlHttp==null)
    {
      alert ("Your browser does not support AJAX!");
      return;    
    }
    var url="getpersonalinfo.asp"
    url=url+"?worknum="+str;
    url=url+"&sid="+Math.random();
    xmlHttp.onreadystatechange=statechanged;
    xmlHttp.open("get",url,null);
    xmlHttp.send(null);    
}

function statechanged()
{
    if(xmlHttp.readystate==4)    
    {
        [color=#0000FF]var xmlDoc=xmlHttp.responseXML.documentElement;[/color]
        document.getelementByid("name").innerHtml=xmlDoc.getelementsBytagname("name")[0].childnodes[0].nodevalue;
        document.getelementByid("extension").innerHtml=xmlDoc.getelementsBytagname("extension")[0].childnodes[0].nodevalue;
    }    
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}



getpersonalinfo.aspÒ³Ãæ
VBScript code

<%
response.Expires=-1
response.contenttype="text/xml"
response.Charset="utf-8"
%>

<!--#included file="inc/conn.asp"-->
<!--#included file="inc/function.asp"-->

<%
dim worknum
dim rs,sql

worknum=trim(request.QueryString("worknum"))

set rs=server.CreateObject("adodb.recordset")
sql="select * from employee where wcode='"&worknum&"'"

rs.open sql,conn,1,3

if not(rs.bof and rs.eof) then
    response.write("<?xml version='1.0' encoding='utf-8'?>")
    response.write("<personalinfo>")
    response.write("<name>"&rs("name")&"</name>")
    response.write("<division>"&rs("div")&"</division>")
    response.write("<dept>"&rs("dept")&"</dept>")
    response.write("<extension>"&rs("extension")&"</extension>")
    response.write("<email>"&rs("email")&"</email>")
    response.write("</personalinfo>")
end if
rs.close
set rs=nothing
%>



ÎÊÌâ:ÈçÉÏ´úÂëÀ¶É«ÐÐ,xmlHttp.responseXML.documentElement·µ»ØµÄÖµÕâ¿Õ,ÓÃalertÊä³öxmlHttp.responsetextÓÐÖµ·µ»Ø,alertÊä³öxmlHttp.responseXMLΪ[object],²»ÖªµÀÕâÊÇʲôԭÒò,·µ»ØxmlHttp.responseXML.documentElementµÄֵΪNULL?
  Ïà¹Ø½â¾ö·½°¸