DragonWar% 2015-06-21 23:58 采纳率: 0%
浏览 39

检索自述文件的HTML

Hi so first time working with APIs like this. Anyways, I've been reading up on the GitHub API and came across this:

READMEs support custom media types for retrieving the raw content or rendered HTML.

src: https://developer.github.com/v3/repos/contents/#get-the-readme

Which I believe means that it is possible to retrieve an HTML formatted version of the contents of the README? If so how would I retrieve it using AJAX since the tutorials are all for curl. In the end I want to display a portion of it on my website and would be a lot easier if given in the html format rather then markdown.

The docs say something about: application/vnd.github.VERSION.html

I just don't necessarily know how to use it.

Thanks!

  • 写回答

2条回答 默认 最新

  • 乱世@小熊 2015-06-22 00:18
    关注

    You have to set the Accept header of the HTTP request to application/vnd.github.html.

    $.ajax({
      url: 'https://api.github.com/repos/just95/toml.dart/readme',
      headers: { 'Accept': 'application/vnd.github.html' }
    }).done(function(data) {
      alert(data);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    </div>
    
    评论

报告相同问题?