您的位置:首页 > Web前端 > JavaScript

javascript + asp 实现javascript跨域读取xml文件

2008-06-20 13:43 465 查看
a.html
<script >
function getPeiLvData()
{
var xmlHttpObj=createXMLHTTP();
xmlHttpObj.onreadystatechange=function(){
if (xmlHttpObj.readyState==4)
{
if (xmlHttpObj.status==200)
{
alert(xmlHttpObj.responseText);xmlHttpObj=null;
} } }
xmlHttpObj.open("post","readXML.asp",true);
xmlHttpObj.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlHttpObj.send(true);
}
getPeiLvData();
</script>

readXML.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%response.charset="gb2312"%>
<%
filePath="http://www.xx.com/xml/xx.xml"
response.write getXML(filePath)
function getXML(url)
dim sttp
set sttp=server.createobject("MSXML2.XMLHTTP")
sttp.open "GET",url,false, "", ""
sttp.send()
if sttp.readystate<>4 then
exit function
end if
getXML=sttp.responseBody
set sttp=nothing
end function
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: