Github's markdown API and Javascript
Github's markdown API and Javascript
我正试图发送一些文本到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);
}
});
相关文章:
- Backbone and PHP API
- YouTube iframe API and WordPress
- Instagram API access_token request and Access-Control-Allow-
- Twitter API and Node
- Ajax and Google Places API getting json
- Yii2 and Google maps API
- Durandal JS and Google Plus Sign in Javascript API
- Google Maps API V3 and Internet Explorer
- Fetch API and Cordova
- Node.js and Express - 将JSON对象从SoundCloud API发送到前端使其成为字符串
- HTML5 Audio, Web Audio API, CORS and Firefox
- Flickr API OAuth Access Token request and Access-Control-All
- JS Fetch api and Symfony2 FOSRestBundle
- Facebook javascript api and iPad, Android
- Blogger JSON API Post fetch and Content Parse
- smartystreets API and post back issue
- Github's markdown API and Javascript
- Weather API and JSON
- Google Maps (JavaScript API) and Tablet Touch Events
- Asp.NET Web API and SignalR Cors