0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【jQuery】rss(xmlデータ)取得

Last updated at Posted at 2021-03-07

rss 取得の仕方メモ

var BlogXmlUrl = "https://media.sample.jp//rss.xml?_=1234567"

function(){

  $.ajax({
    url: BlogXmlUrl 
  }).done(function(data, textStatus, jqXHR){ //成功 textStatusにはsuccess or error、jqXHRはXMLHttpRequestオブジェクト(200→成功、404→エラー)
    var $items = $(data).find("item");
      console.log($items);

    $items.each(function(i, e) { //iはindex eはelement(要素)
      console.log(i, e);
      if(i<3) {
        var target = $('.rss-blog'); //rssで取得した要素の吐き出し先

        var date = $(this).find("date").text()
        var title = $(this).find("title").text()
        var description = $(this).find("description").text()

        var html = ''; // += で 要素追加してく
        html +=  '<date class="blog-content-date">'+ date + '</date>';
        html +=  '<h2 class="blog-content-title">'+ title + '</h2>';
        html +=  '<p class="blog-content-description ">'+ description + '</p>';

        target.append(html)
      }
    });
  }).fail(function(jqXHR, textStatus, errorThrown){ //失敗 jqXHRはXMLHttpRequestオブジェクト(200→成功、404→エラー)
    console.log(jqXHR)
  })

};

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?