希望对你有帮助 a.html <script > // 创建xmlhttprequest 对象。 function createXMLHTTP() { ...... } function getData() { 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); } getData(); </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 %>
我是这么做的
还可以用json 你看看baidu的代码 他们也是跨域的 动态script块 通过json传送数据也可以跨域
问题是这样的 我自己的域名www.aaa.com/1.html 要获取www.baidu.com/s?wd=a&ch=&tn=360se_dg&bar= 页面的代码 请问用什么办法?? 最好有实例谢谢
a.html
<script >
// 创建xmlhttprequest 对象。
function createXMLHTTP() {
......
} function getData() {
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); }
getData();
</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
%>