2011-09-24 44 views
0

我正在使用jFeed解析原子提要並嘗試顯示標題。我寫過成功和錯誤函數,但它沒有涉及成功或錯誤函數。無法使用jQuery解析原子提要

以下是我的代碼。請讓我知道下面的代碼出了什麼問題。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Insert title here</title> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> 
<script type="text/javascript" src="javascript/jquery.jfeed.js"></script> 

<script type="text/javascript"> 

$(document).ready(function(){ 

//read the atom feed 

$.getFeed({ 
    type:"GET", 
    url:"http://www.google.co.in/trends/hottrends/atom/hourly", 
    success:function(feed) 
    { 
     alert(feed.title); 
    }, 
    error:function(error) 
    { 
     alert(error); 
    } 

}); 


}); 

</script> 
</head> 
<body> 
<div id="content"></div> 
</body> 
</html> 
+0

我看,你的例子和jfeeds一樣。但返回數據通常是一個列表而不是單個項目,對嗎?爲什麼你只是不要在「alert(feed.title)」處設置一個斷點,將鼠標懸停在feed上並查看對象內部的真實內容? – Luke

回答

0

$ .getFeed不帶「type」和「error」參數。

從jfeed來源:

jQuery.getFeed = function(options) { 

options = jQuery.extend({ 

    url: null, 
    data: null, 
    success: null 

}, options); 

if(options.url) { 

    $.ajax({ 
     type: 'GET', 
     url: options.url, 
     data: options.data, 
     dataType: 'xml', 
     success: function(xml) { 
      var feed = new JFeed(xml); 
      if(jQuery.isFunction(options.success)) options.success(feed); 
     } 
    }); 
} 

,所以你最有可能得到一個錯誤。

嘗試發送一個簡單的Ajax請求,看看你正在得到什麼錯誤。

+0

現在我已經只把網址和成功,但它仍然沒有顯示任何 – JavaGeek

+1

你需要尋找錯誤..首先發送$ .ajax({類型:'GET',url:yoururl,dataType:'xml',錯誤:函數(jqXHR,textStatus,errorThrown){alert(textStatus);}); – karnyj

+0

我添加了.ajax(),它進入了錯誤函數,但仍然只是錯誤消息。 http://jsfiddle.net/sukumar/sWPkT/ – JavaGeek