【问题标题】:read markdownfile via jQuery.get()通过 jQuery.get() 读取 markdownfile
【发布时间】:2016-06-06 05:17:57
【问题描述】:

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

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/
 - [...]

在我调用 jQuery.get() 来读取 markdown 文件的 html 文件的代码下方。可在 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 文件的内容,以便使用?

【问题讨论】:

    标签: javascript jquery html get markdown


    【解决方案1】:

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

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

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

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

    DEMO

    【讨论】:

    • 谢谢。作品!我在本地测试了它(没有服务器)。 readme.md 现在已读取,因此我可以在 console.log 中看到它,但是 textarea 字段的更新(正如您在演示中所拥有的那样)不起作用。可能是本地测试造成的……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-02
    相关资源
    最近更新 更多