目前主要有三种方法:

1、Application Proxies :这种必须通过后台脚本读取异域数据并返回给 Ajax 显示:

文件名称:demo.php
  1. <?php
  2. define(‘HOSTNAME’, ‘http://www.douwo.cn/’);
  3. $path = $_GET[‘path’];
  4. $url = HOSTNAME.$path;
  5. // Open the Curl session
  6. $session = curl_init($url);
  7. // Don’t return HTTP headers. Do return the contents of the call
  8. curl_setopt($session, CURLOPT_HEADER, false);
  9. curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  10. $xml = curl_exec($session);
  11. header(“Content-Type: text/xml”);
  12. echo $xml;
  13. 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
# Apache’s mod_rewrite
RewriteEngine on
RewriteRule ^/call/(.*)$ http://www.douwo.cn/$1 [P]

发表评论

电子邮件地址不会被公开。 必填项已用*标注