ajax+xml的asp查询代码

数据库中表名ly,字段名y_username,y_message,y_timeindex.html<HTML><HEAD><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"><TITLE>MyDocuments</TITLE></HEAD><style><!–body{font-size:12px;}–></style><BODY><formname="form1"method="post"><inputtype="text"name="search">&nbsp;<inputtype="button"value="查询"onclick="javascript:f1()"></form><divid="disp"></div></BODY></HTML><scriptlanguage="javascript">functionf1(){if(document.form1.search.value==""){alert(‘请输入要查询的内容’);returnfalse;}varxmlhttp;varsearch;vars="";search=document.form1.search.value;varxmlhttp;try{xmhttp=newActiveXObject("Msxml2.XMLHTTP");}catch(e){try{xmlhttp=newActiveXObject("Microsoft.XMLHTTP");}catch(e){try{xmlhttp=newXMLHttpRequest();}catch(e){}}}xmlhttp.onreadystatechange=function(){if(4==xmlhttp.readyState){if(200==xmlhttp.status){varxmldoc=xmlhttp.responseXML;varmessage_nodes=xmldoc.getElementsByTagName("message");varn_messages=message_nodes.length;for(i=0;i<n_messages;i++){varuser_node=message_nodes[i].getElementsByTagName("user")[0].firstChild.data;vartext_node=message_nodes[i].getElementsByTagName("text")[0].firstChild.data;vartime_node=message_nodes[i].getElementsByTagName("time")[0].firstChild.data;s=s+"<b>用户名:</b>"+user_node+"<br><b>留言:</b>"+text_node+"<br><b>发言时间:</b>"+time_node+"<br><br>";}document.getElementById("disp").innerHTML=s;}else{alert(xmlhttp.status);}}}varurl="search.asp?search="+escape(search)+"&t="+newDate().getTime();xmlhttp.open("get",url);xmlhttp.send(null);}</script>search.asp<!–#includefile="adoconn.asp"–><%text=Trim(request("search"))sql="selecty_username,y_message,y_timefromlywherey_usernamelike’%"&text&"%’orderbyy_timedesc"rs.opensql,conn,1,1Ifrs.eofThenstr="error"ElseResponse.ContentType="text/xml"str="<?xmlversion=""1.0""encoding=""gb2312""?>"&vbnewlinestr=str&"<root>"&vbnewlinei=1DoWhileNotrs.eofstr=str&"<messageid="""&i&""">"&vbnewlinestr=str&"<user>"&rs("y_username")&"</user>"&vbnewlinestr=str&"<text>"&rs("y_message")&"</text>"&vbnewlinestr=str&"<time>"&rs("y_time")&"</time>"&vbnewlinestr=str&"</message>"&vbnewlinei=i+1rs.movenextloopstr=str&"</root>"EndIfresponse.writestrrs.closesetrs=nothingconn.closesetconn=nothing%>不必在乎目的地,在乎的是沿途的风景以及看风景的心情,让心灵去旅行!

ajax+xml的asp查询代码

相关文章:

你感兴趣的文章:

标签云: