Javascript craigslist rss提要

Javascript craigslist rss提要,javascript,jquery,xml,rss,Javascript,Jquery,Xml,Rss,我正试图解析craigslist rss源中的数据 这是提要url- 我正在使用jfeed,下面给出了我的代码 jQuery(function() { jQuery.getFeed({ url: 'proxy.php?url=http://www.craigslist.org/about/best/all/index.rss', success: function(feed) { jQuery('#result')

我正试图解析craigslist rss源中的数据

这是提要url-

我正在使用jfeed,下面给出了我的代码

jQuery(function() {

    jQuery.getFeed({
        url: 'proxy.php?url=http://www.craigslist.org/about/best/all/index.rss',
        success: function(feed) {        
            jQuery('#result').append('<h2>'
            + feed.title
            + '</h2>');                                

        }    
    });
});
jQuery(函数(){
jQuery.getFeed({
url:'proxy.php?url=http://www.craigslist.org/about/best/all/index.rss',
成功:函数(提要){
jQuery('#result').append(''
+feed.title
+ '');                                
}    
});
});
但是,我没有显示提要标题或提要的任何其他属性。如果我只是尝试将提要打印到屏幕上,我会得到“Object Object”,这意味着它正确地返回了提要


有人知道我遗漏了什么吗?

首先:您无法从另一个域获取数据,因为策略无效。我不知道jfeed,但在我的项目中,我提出了这个解决方案。通过这个简单的函数,您可以节省一些带宽和代码开销

工作示例

proxy.php(src:)


首先:您无法从另一个域获取数据,因为策略无效。我不知道jfeed,但在我的项目中,我提出了这个解决方案。通过这个简单的函数,您可以节省一些带宽和代码开销

工作示例

proxy.php(src:)


或者,您可以使用其他服务读取RSS提要并将其转换为JSON,如果您无法访问任何服务器端环境,这将非常有用

为此,我通常使用YQL,但肯定还有其他服务


下面是一个使用craigslist的工作示例,源代码为:

或者,您可以使用其他服务来读取RSS提要并将其转换为JSON,如果您无法访问任何服务器端环境,这将非常有用

为此,我通常使用YQL,但肯定还有其他服务


下面是一个使用craigslist的工作示例,源代码为:

当您使用“console.log”将对象记录到Firebug时会发生什么?我检查了,它显示的描述、标题和链接为空。如果我直接使用web浏览器打开craigslist url并查看页面源代码,我可以看到标题、链接、说明等的值,etcjfeed的示例-proxy.html在这里工作w/。加载需要一段时间,但标题和所有其他属性都在那里。当您访问“yoursite.com/proxy.php?url=”时,您是否看到与访问CL上的实际提要时相同/正确的输出?当您使用“console.log”将对象记录到Firebug时会发生什么?我检查了,它显示的描述、标题和链接为空。如果我直接使用web浏览器打开craigslist url并查看页面源代码,我可以看到标题、链接、说明等的值,etcjfeed的示例-proxy.html在这里工作w/。加载需要一段时间,但它仍然有标题和所有其他属性。当您访问“yoursite.com/proxy.php?url=”时,您是否看到与访问CL上的实际提要时相同/正确的输出?
<?php
// Set your return content type
header('Content-type: application/xml');

// Website url to open
$daurl = 'http://www.craigslist.org/about/best/all/index.rss';

// Get that website's content
$handle = fopen($daurl, "r");

// If there is something, read and return
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>
$.ajax({
    type: "GET",
    url: "proxy.php",
    dataType: "xml",
    success: parseXml
 });

function parseXml(xml) {
    console.log(xml);
    $(xml).find("item").each(function() {
        var content = $(this).find("title").text()
        $("#news_list").append('<li>' + content +'</li>');
    });
}
<div id="news_list"></div>