【发布时间】:2016-10-12 01:54:07
【问题描述】:
我想从另一个网站更新我的Gist,我使用我的 gist 令牌登录。我无法让它工作。我设法通过 GET 获得了要点,但使用 PATCH 更新要点不起作用。
我不认为这是身份验证的问题,因为在获得要点时,我的用户名和个人资料显示正确。
JavaScript (JQuery):
$.ajax({
url: 'https://api.github.com/gists/e3e0b182c09bf333593c',
type: 'PATCH',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization","token f32e-----MY-TOKEN-(GIST-ACCESS)-----6f44");
}, data: {
"description":"Edit gist",
"files":{
"annexation.json":{
"content":"{\"updated content\":\"from Ajax\"}"
}
}
}
}).done(function(response) {
$('#write').text(JSON.stringify(response));
});
我不断收到错误 400(错误请求)。
回复:
{
"message": "Problems parsing JSON",
"documentation_url": "https://developer.github.com/v3/gists/#edit-a-gist"
}
如果我做错了什么,有人可以指出吗?非常感谢。
【问题讨论】:
标签: javascript json ajax xmlhttprequest gist