2010-01-14 94 views
1

我試圖抓住通過AJAX http://lib.softvoyage.com/cgi-bin/gate_dest_hotels.xml?code_ag=nwi&alias=tpi&language=en&with_cdata=y但是它一直返回nadda(螢火蟲截圖在這裏:http://img683.imageshack.us/img683/3279/firebug.jpg)一個空文件JQuery的AJAX GET返回

下面是代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
     <title>Search Form</title> 
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
    </head> 
    <body> 
     <form method="post" action="#"> 
      <label for="gateway_dep">Leaving From:</label> 
      <select id="gateway_dep" name="gateway_dep"> 
       <option value="">Select a gateway</option> 
       <option value=""></option> 
       <option value="">Loading gateways</option> 
      </select> 
     </form> 
     <script type="text/javascript"> 
     <!-- 
      $(document).ready(function() { 
       $.ajax({ 
        url:"http://lib.softvoyage.com/cgi-bin/gate_dest_hotels.xml?code_ag=nwi&alias=tpi&language=en&with_cdata=y", 
        cache:false, 
        dataType:"text", 
        type:"GET", 
        success:function(xml) { 
         alert(xml); 
        } 
       }); 
      }); 
     --> 
     </script> 
    </body> 
</html> 

回答

1

您只能使用AJAX在與當前頁面相同的域中的頁面上。如果你想從外部源獲取數據,你將不得不使用getJSON函數,而其他站點必須以getJSON可以處理的形式返回數據。

或者,您可以有一個服務器端代理,在服務器端執行獲取請求,而AJAX限制不存在,然後將數據返回到您的頁面。

+0

啊你說得對,因爲某些原因,跨域甚至沒有進入我的想法作爲一個問題 – 2010-01-14 20:10:11