2013-04-15 55 views
-1

我想從僅使用javascript和ajax的網頁獲取數據。我的網頁正在返回一個數組,我想在我的html頁面上顯示。我不能用這個PHP。我如何從使用AJAX的網頁獲取數據?

這是我正在使用的代碼。

<html> 
    <head> 
     <title>Getting Started Extension's Popup</title> 
     <script src="background.js"> 
     </script> 
     <script type="text/javascript"> 
      $.ajax({ 
       url:"http://www.mydomain.com/page1.php?url='http://open.live.bbc.co.uk/weather/feeds/en/2643743/3dayforecast.rss'", 
       type: 'GET', 
       dataType: 'jsonp' 
      }); 

      function callback(data){ 
       $('#iec_azn_data').html(data.results[0]); 
      } 
     </script> 
    </head> 
    <body> 
     Hi 
     <div id="iec_azn_data"> 

     </div> 
    </body> 
</html> 
+1

在ajax請求中使用成功。成功:功能(數據){//你的代碼} – Dineshkani

回答

1

$.ajax選擇一個函數分配給success。當你的請求成功返回時,該函數被調用。

$.ajax({ 
    url:"http://www.mydomain.com/page1.php?url='http://open.live.bbc.co.uk/weather/feeds/en/2643743/3dayforecast.rss'", 
    type: 'GET', 
    dataType: 'jsonp', 
    success : function(data){ 
    //data is a variable containing the returned data 
    } 
}); 
+0

現在我有這個JavaScript但仍然沒有呈現任何東西

+0

@Keyur什麼是返回數據?是HTML還是其他? – Joseph

+0

返回數據是簡單的html表 –