当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 成功实现ajax,xmlhttp跨域访问

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 成功实现ajax,xmlhttp跨域访问


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 417 ::
收藏到网摘: n/a

这几天脑细胞剩下的不多了,不过问题都一个个解决了。
我希望搜索引擎能够搜索到这篇文章,给正在需要解决此类问题的朋友分享我的解决方案。

例如
a.com站点通过ajax访问聚合b.com站点内的RSS(xml)资源,这是跨域访问不能实现,网上我也查阅了大量的资料,没有找到有效的办法,有些变通的方法都必须具有b.com站点的权限对b.com站点进行设置才行。

a.com站点聚合b.com站点内RSS资源方法如下:
ajax部分不作详细说明。
在a.com内使用动态网页(ASP、PHP、JSP或者其他l)作为代理读取b.com中rss内容,再在a.com中使用ajax读取分析该动态网页。
PHP代码:
<?
echo file_get_contents("http://b.com/rss.xml");
?>


ASP代码:
<%
p = "http://b.com/rss.xml"
Response.BinaryWrite ZQcnGet(p)
Response.Flush
Function ZQcnGet(url)
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
ZQcnGet = .ResponseBody
End With
Set Retrieval = Nothing
End Function
%>


JSP代码:
<%
URLUtil util = new URLUtil("http://b.com/rss.xml");
String news = util.getContent();
System.out.println(news);
%>

接下来在a.com中使用ajax读取分析该动态网页就ok了.