2015-07-21 48 views
0

我有我的網站上這樣的代碼:

$.ajax({ 
     type: "GET", 
     url: 'http://www.rp-online.de/cmlink/top-news-1.2513701', 
     cache : false, 
     dataType: "xml", 
     success: function(xml) { 
      $(xml).find('title').text(); 
      console.log($(xml).text()); 

      var as = $(xml).find('description').eq(1).text(); 
      $('#av').append(as); 
     }, 
     error:function (xhr, textStatus, thrownError){ 
      console.log(textStatus); 
      $("#result").html(textStatus); 
     } 
    }); 

現在,此代碼的工作,其用於從其他網站(RSS源)獲取數據。

一切看起來不錯,在桌面,IOS,但不是在Android上。 當我打開Chrome和移動仿真時,我在控制檯中看到這個: parseerror。 有人知道解決方案嗎? 謝謝。

回答

0

你的jquery代碼工作正常。我在我的電腦上使用Android模擬器在本機和Chrome瀏覽器上進行了測試,在這裏我有enter image description here

也許您在HTML中遇到問題。檢查你是不是複製「IDS」

<html> 
    <head> 
    <title></title> 
    <script src="jquery.js"></script> 
    <script> 

    $.ajax({ 
    type: "GET", 
    url: 'http://www.rp-online.de/cmlink/top-news-1.2513701', 
    cache : false, 
    dataType: "xml", 
    success: function(xml) { 
     $(xml).find('title').text(); 
     console.log($(xml).text()); 

     var as = $(xml).find('description').eq(1).text(); 
     $('#av').append(as); 
    }, 
    error:function (xhr, textStatus, thrownError){ 
     console.log(textStatus); 
     $("#result").html(textStatus); 
    } 
}); 

    </script> 
    </head> 
    <body> 
     <div id="result"></div> 
     <div id="av"></div> 

    </body> 
    </html> 
0

我確認,這上面的代碼將只適用於iPad,Nexus 7保護工作,但不支持其他設備。爲iPad頭是:

狀態碼:200 OK 內容類型:應用/ RSS + xml的;字符集= UTF-8

而對於iPhone: 狀態碼:301移到永久 內容類型: text/html