我无法将jQuery.ajax()
要点发布到 Github。要点已创建,响应为201 Created
,但 Firebug 中的响应选项卡为空,并命中错误回调。
var data = {
"description": "posting gist test",
"public": true,
"files": {
"test.txt": {
"content": "hello gist!"
}
}
}
$.ajax({
url: 'https://api.github.com/gists',
type: 'POST',
dataType: 'json',
data: JSON.stringify(data)
})
.success( function(e) {
console.log(e);
})
.error( function(e) {
console.warn("gist save error", e);
});
令人沮丧的是,它在 jsfiddle 中运行良好:http: //jsfiddle.net/vXpCV/
也许这就是问题所在。jsFiddle 得到不同的响应头:
Access-Control-Allow-Cred... true
Access-Control-Allow-Orig... http://fiddle.jshell.net
Access-Control-Expose-Hea... Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-OAuth-Scopes, X-Accepted-OAuth-Scopes
Connection keep-alive
Content-Length 1093
Content-Type application/json; charset=utf-8
...