2015-01-07 30 views
0

我想呈现此url http://online.wsj.com/xml/rss/3_7085.xml使用jquery获取所有的xml信息,但我碰到了jsonp上的东西这给我一个回调,我该如何处理回调来呈现html中的每个节点。想要获取RSS源和呈现在html上使用jquery

我尝试下面的代码:

<!DOCTYPE HTML> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>RSS Feed testing</title> 
 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
 
<script> 
 
    var result; 
 
    function jsonparser1() { 
 
     $.ajax({ 
 
      type: "GET", 
 
      url: "http://online.wsj.com/xml/rss/3_7085.xml", 
 
      dataType: "jsonp", 
 
      success: function (result) { 
 
       $("div").html(result); 
 
       
 
      }, 
 
     }); 
 
    }   
 
\t 
 
\t $(document).ready(function(e) { 
 
     jsonparser1(); 
 
    }); 
 
</script>  
 
</script> 
 
</head> 
 

 
<body> 
 
<div></div> 
 

 
</body> 
 
</html>

我一派,约JSONP,其相当混乱给我。

+1

除非wsj启用了CORS,否则它不会因为相同原点策略而发生,并且您无法使JSONP发生,您调用的服务器必须支持它。 – epascarello

回答

0

以xml格式提供的Rss订阅源。使用datatype = json。

function jsonparser1() { 
    $.ajax({ 
     type: "GET", 
     url: "http://online.wsj.com/xml/rss/3_7085.xml", 
     dataType: "xml", 
     success: function (result) { 
      $("div").html(result); 

     }, 
    }); 
} 
+0

rss在xml节点中,我尝试了所有的数据类型= json或jsonp或xml,但没有结果。在注意它的XML格式,为什么我会写json作为数据类型? –

+0

由于您的问题的评论中解释了CSP,因此这不起作用。 –

0

这是不可行的。您需要使用像Superfeedr's Feed APIGoogle's这样的服务。

这些服务将使用JSONP为您的JSON提要提供内容,以便您可以轻松地将任何提要集成到任何页面中。