通过 jQuery.get() 读取 markdown 文件

read markdownfile via jQuery.get()

我尝试通过 jQuery.get() 读取 markdown 文件的内容,以便我可以使用 markdown 内容。但它不起作用。

Firebug 控制台报告如下:

start logging            ondex.html:17:4
end logging              ondex.html:21:4
not wellformed           readme.md:1:2
not wellformed           ondex.html:1:2

文件 readme.md 已读取,但格式不正确。我想,这会导致麻烦...

这是降价文件。 Github 也可用:readme.md

# jerik.github.io
snippset and things I want to capture / document

## todos
- Integrate Navigation dropdown with my pages. The page names should be stated in a tag ( meta-tag, own-tag.. ), so that it can be read by js. 
 - For Layout see: https://bootswatch.com/cerulean/
 - [...]

在 html 文件的代码下方,我调用 jQuery.get() 来读取降价文件。在 Github ondex.html

可用
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>Jerik's this and that</title>
  <meta name="description" content="Some stuff that I want to mention" />
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <script type="text/javascript" charset="utf-8">
    // [...]

    console.log( 'start logging' );
    $.get( "readme.md", function( data ) {
        console.log( data ); // this is not called !!
    });
    console.log( 'end logging' );

  </script>
</head>
<body>
<center>das iste in test</center>
<textarea id="ta" theme="cerulean" style="display:none;">
hallo
</textarea>
<script src="v/0.2/strapdown.js"></script>
</body>
</html>

如何获取 markdown 文件的内容,以便我可以使用它?

尝试将 dataType 显式设置为 "text"

$.get( "readme.md", function( data ) {
        console.log( data ); 
},'text');

我可以在不这样做的情况下在 plunker 演示中得到它,但这可能是你的服务器为文件设置了不同的 headers 并且 jQuery 猜测数据类型可能在内部以不同的方式处理它

如有疑问,请检查浏览器开发工具网络中的实际响应 body,以查看实际收到的内容

DEMO