目前主要有三种方法:
1、Application Proxies :这种必须通过后台脚本读取异域数据并返回给 Ajax 显示:
文件名称:demo.php
- <?php
- define(‘HOSTNAME’, ‘http://www.douwo.cn/’);
- $path = $_GET[‘path’];
- $url = HOSTNAME.$path;
- // Open the Curl session
- $session = curl_init($url);
- // Don’t return HTTP headers. Do return the contents of the call
- curl_setopt($session, CURLOPT_HEADER, false);
- curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
- $xml = curl_exec($session);
- header(“Content-Type: text/xml”);
- echo $xml;
- curl_close($session);
2、Script tag hack with application proxy or On-Demand JavaScript: (doesn’t use XMLHttpRequest at all) Use the HTML script tag to make a request to an application proxy that returns your data wrapped in JavaScript. This approach is also known as On-Demand JavaScript.
不使用AJAX,前台异步加载JS数据,发送请求后,后台程序读取异域数据赋值给一个变量直接发送给前台。
3、Apache Proxy : apache’s mod_rewrite or mod_proxy 速度较快些
# Proxy :Pass the call from http://www.yourserver.com/call to http://www.douwo.cn
ProxyPass /call/ http://www.douwo.cn
ProxyPassReverse /call/ http://www.douwo.cn
ProxyPass /call/ http://www.douwo.cn
ProxyPassReverse /call/ http://www.douwo.cn