Github's markdown API and Javascript

Github's markdown API and Javascript

本文关键字:API and Javascript markdown Github      更新时间:2023-09-26

我正试图发送一些文本到Github的降价API,并得到它的原始HTML表示。

目前我有这个代码:

    $.ajax({
        type: "POST",
        dataType: "jsonp",
        processData: false,
        url: "http://api.github.com/markdown/raw",
        data: {
            "text": $('#some_textarea').val()
        },
        success: function(data){
            console.log("success!");
            console.log(data);
        }, 
        error: function(jqXHR, textStatus, error){
            console.log(jqXHR, textStatus, error);
        }
    });

但我得到"错误"(textStatus在error回调)。我做错了什么?

你需要发布到HTTPS而不是HTTP,如果你使用原始API,那么

  • 发布的内容类型需要为text/plain
  • API返回html内容,而不是JSON或JSONP

。jsfiddle

$.ajax({
    type: "POST",
    dataType: "html",
    processData: false,
    url: "https://api.github.com/markdown/raw",
    data: "Hello world github/linguist#1 **cool**, and #1!",
    contentType: "text/plain",
    success: function(data){
        console.log("success!");
        console.log(data);
    }, 
    error: function(jqXHR, textStatus, error){
        console.log(jqXHR, textStatus, error);
    }
});