【发布时间】:2011-02-11 00:40:57
【问题描述】:
我正在使用 JQuery 的 $.get 函数来获取 twitter 提要并将其显示在我的网站上。我不知道为什么它似乎没有得到任何数据(即 function(d) { ... } 中的代码没有被调用)。它在我尝试过的所有其他东西中都可以正常工作。我之前也用过这段代码没有问题,我唯一能想到的就是它是通过https运行的。
(请注意,对于示例,我已从提要 url 中删除了 twitter 用户 ID)
JS:
$.get('proxy.php?url=http://twitter.com/statuses/user_timeline/999999999.rss', function(d) {
$(d).find('item').each(function() {
var theItem = $(this);
var title = theItem.find('title').text();
var date = new Date(theItem.find('pubDate').text());
var alink = theItem.find('link').text();
// code ommitted (inserts tweet into page)
});
});
proxy.php:
<?php
// PHP Proxy
// Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions
// Author: Paulo Fierro
// January 29, 2006
// usage: proxy.php?url=http://mysite.com/myxml.xml
$session = curl_init($_GET['url']); // Open the Curl session
curl_setopt($session, CURLOPT_HEADER, false); // Don't return HTTP headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call
$xml = curl_exec($session); // Make the call
$seconds_to_cache = 300; // five mins (60 * 5)
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
header("Cache-Control: maxage=$seconds_to_cache");
//header("Content-Type: text/xml"); // Set the content type appropriately
header("Content-Type: application/rss+xml");
echo $xml; // Spit out the xml
curl_close($session); // And close the session
?>
任何想法/帮助将不胜感激
【问题讨论】:
-
它在什么时候中断?该脚本是否设法获取任何数据?你有什么错误吗?
-
不应该是
"Expires: ".$ts和"Cache-Control: maxage=".$seconds_to_cache吗? -
PHP 脚本似乎工作正常,我确实按照您的建议更改了这些变量以确保安全,但是当在地址栏中物理访问 url 时,它会按预期呈现提要,并且可以正常工作在其他浏览器中很好。我没有收到任何 JS 错误,它只是默默地失败。如果我在函数内(即在 $(d).find 行之前)放置警报,则不会显示。
标签: php jquery ajax internet-explorer get