ΪʲôȡxmlHttp.responseXML.documentElementȡΪ¿Õ? - Web ¿ª·¢ / Ajax
ÒªÇó,ÔÚaspÒ³ÃæÖÐÊäÈ빤ºÅÏîÖÐÊäÈ빤ºÅ,×Ô¶¯ÔÚ¸ÃÒ³ÃæÖÐÏÔʾ¸Ã¹¤ºÅµÄÏà¹ØÊý¾Ý,±ÈÈç¶ÔÓ¦µÄÐÕÃû,µç»°µÈ.
Ïëµ½ÓÃAjax ʵÏÖ,´úÂëÈçÏÂ:
a.aspÒ³Ãæ,¸Ã²¿·ÖHTML´úÂëÊ¡ÂÔ.
.....<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>
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;}
<%response.Expires=-1response.contenttype="text/xml"response.Charset="utf-8"%><!--#included file="inc/conn.asp"--><!--#included file="inc/function.asp"--><%dim worknumdim rs,sqlworknum=trim(request.QueryString("worknum"))set rs=server.CreateObject("adodb.recordset")sql="select * from employee where wcode='"&worknum&"'"rs.open sql,conn,1,3if 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 ifrs.closeset rs=nothing%>
[½â¾ö°ì·¨]
alert(xmlHttp.responsetext); ·µ»ØµÄÖµÊÇʲô£¿Ìù³öÀ´¿´¿´¡£
[½â¾ö°ì·¨]
aspµÄÎÒûÓÐд¹ý
jspÀïÃæ¾ÍÊǺܼòµ¥µÄ
1£º²âÊÔºǫ́ÊÇ·ñÄÜ·µ»ØÊý¾Ý
2£ºÕýÈ·µÄÏÔʾÔÚÒ³ÃæÉÏÊý¾Ý È磺 innerHTML
[½â¾ö°ì·¨]
http://hi.baidu.com/bxba/blog/item/653362597dbd9b222834f0d6.html
ÎÒʹÓõÄajax´úÂë