2016-08-25 3 views
0

RSS 피드를 가져와 apache cordova를 통해 모바일 장치에 내용을 표시하려고합니다. 그러나 .xml 파일을 가리키는 URL을 제공하지 않으면 판독기가로드되지 않습니다. 예를 들어,jQuery/Apache Cordova로 rss 피드 가져 오기

var feedUrl = "https://newsline.com/feed/"; 

이로드되지 않습니다,하지만 난

var feedUrl = "http://feeds.bbci.co.uk/news/technology/rss.xml"; 

를 사용하는 경우 작동합니다.

/** 
* Fetch RSS and display the contents of it 
*/ 
Feed.prototype.load = function() { 
    var self = this; 

    $(this.maskEl).show(); 
    $(this.errorEl).text(''); 

    $.ajax({ 
     url: this.url, 
     dataType: 'text', 
     crossDomain: true, 
     success: function(data) { 
      data = $.parseXML(data.trim()); 

      $(self.listEl).empty(); 

      // Display RSS contents 
      var $rss = $(data); 
      $rss.find('item').each(function() { 
       var item = this; 
       $(self.listEl).append(self.createListElement(item)); 
      }); 
     }, 
     error: function() { 
      $(self.errorEl).text('Failed to load RSS.'); 
     }, 
     complete: function() { 
      $(self.maskEl).hide(); 
     } 
    }); 
}; 

을하고 index.html 페이지에 : 어떤 도움을 주시면 감사하겠습니다

var feedUrl = "https://newsline.com/feed/"; 

    $(function() { 

     var feed = new Feed({ 
      url: feedUrl 
     }); 

     if (monaca.isIOS) { 
      $('.toolbar').css('margin-top', '20px'); 
      $('.button').css('top', '20px'); 
     } 

     $('.button').click(function() { 
      console.log('Reload.'); 
      feed.load(); 
     }); 

     feed.load(); 

    }); 

여기 내가 사용하고 자바 스크립트 파일은 RSS 리더입니다. 나는 그것이 feed-reader.js에서 xml의 실제 구문 분석과 관련이 있다고 생각하지만 완전히 확신 할 수는 없다.

감사합니다.

업데이트 :

나는 URL이 의도 한대로 작동,하지만 지금은 문제가 있어요 내가 피드에 기사를 클릭 한 후 홈 페이지로 다시 이동하려고 할 때 (가 RSS 피드를 다시로드하지 않습니다 있어요). 코드는 동일합니다. 예를 들어, 여기에 몇 가지 스크린 샷 위치 : Image Screenshots

기본적으로 공급이 홈 페이지에로드하지만있는 링크를 클릭하고, 사용자가 페이지로 이동 한 후 (스크린 샷 참조) 뒤로 화살표를 클릭하면 , 그것은 "RSS를로드하지 못했습니다"라는 오류 메시지와 함께 나타납니다. 페이지가 결과를 다시 얻지 못하는 jQuery 문제입니까? 일단 DOM이 준비되면 실행되도록 설정 했으므로 사용자가 홈 페이지로 돌아 가면 피드가 다시로드되지 않는 이유가 손실됩니다.

다시 도움이 될 것입니다.

+0

으로 사용하는하는 plugin 필요 -은 https : // 문서 .monaca.io/ko/sampleapp/samples/sample_rss_reader/ – Gandhi

+0

xml 참조없이 URL을 작동 시키려면 어떤 변경을 했습니까? –

+0

피드 버너 계정에 URL을 사용했습니다. http://feeds.feedburner.com/newslineEN?format=xml – user2101411

답변

1

소리가 캐싱 문제와 같습니다. 그렇다면 PhoneGap disable caching가 도움이 될 수 있습니다. 당신은 당신이 같은

phonegap local plugin add https://github.com/moderna/cordova-plugin-cache.git 

를 설치하고이 샘플을 살펴 당신을했다 않았다 혹시

document.addEventListener('deviceready', onDeviceReady); 
function onDeviceReady() 
{ 
     var success = function(status) { 
      alert('Message: ' + status); 
     } 

     var error = function(status) { 
      alert('Error: ' + status); 
     } 

     window.cache.clear(success, error); 
} 
+0

여전히로드하는 데 실패하고 있습니다. : \ – user2101411