ajax的 responseXML返回接受 asp
更新時間:2006年11月25日 00:00:00 作者:
第一個文件 index.asp
<script language="javascript">
var xmlHttp = false; //ajax使用
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
function callserver()
{
var url = "index.asp";
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange = update;
xmlHttp.setrequestheader("content-type","application/x-www-form-urlencoded");
xmlHttp.send(null);
}
function update()
{
if(xmlHttp.readystate==4)
{
var xmldoc=xmlHttp.responseXML
var info = xmldoc.getElementsByTagName("info")[0].text;
alert(info);
}
}
callserver();
</script>
第二個 login.asp
<%
Response.ContentType="text/xml"
response.Write("<?xml version='1.0' encoding='GB2312' ?>")
response.Write("<root>")
response.Write("<info>love you</info>")
response.Write("</root>")
%>
<script language="javascript">
var xmlHttp = false; //ajax使用
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
function callserver()
{
var url = "index.asp";
xmlHttp.open("POST",url,true);
xmlHttp.onreadystatechange = update;
xmlHttp.setrequestheader("content-type","application/x-www-form-urlencoded");
xmlHttp.send(null);
}
function update()
{
if(xmlHttp.readystate==4)
{
var xmldoc=xmlHttp.responseXML
var info = xmldoc.getElementsByTagName("info")[0].text;
alert(info);
}
}
callserver();
</script>
第二個 login.asp
<%
Response.ContentType="text/xml"
response.Write("<?xml version='1.0' encoding='GB2312' ?>")
response.Write("<root>")
response.Write("<info>love you</info>")
response.Write("</root>")
%>
相關(guān)文章
AJAX跨域請求JSONP獲取JSON數(shù)據(jù)的實例代碼
Asynchronous JavaScript and XML (Ajax) 是驅(qū)動新一代 Web 站點(流行術(shù)語為 Web 2.0 站點)的關(guān)鍵技術(shù)。Ajax 這篇文章主要介紹了AJAX跨域請求JSONP獲取JSON數(shù)據(jù)的實例代碼,需要的朋友可以參考下2017-02-02關(guān)于多個Ajax請求執(zhí)行返回先后的問題示例探討
這篇文章主要與大家探討下關(guān)于多個Ajax請求執(zhí)行返回先后的問題,需要的朋友可以參考下2014-07-07ajax實現(xiàn)select三級聯(lián)動效果
這篇文章主要為大家詳細介紹了ajax動態(tài)實現(xiàn)select三級聯(lián)動,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01