【发布时间】:2019-12-02 16:31:32
【问题描述】:
我已经通过gitlab api成功接收到用户的id,但是当我尝试接收用户的项目列表时,chrome返回CORB。
我已经使用 GitLab api v4 成功收到了 id 和所有其他用户信息。但是当我试图接收用户的 repo 列表时,我收到了 CORB 块并且在响应文本中一无所获。直接输入网址可以看到json格式的数据。如果我直接使用 jQuery.getJSON,它会要求我在 header 中添加 X-Requested-With 或 Origin,我不知道如何实现。
var target = 'https://gitlab.com/api/v4/users/'+doc.data().gitlab_id+'/projects?callback=?';
console.log(target);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = process;
xhr.open("GET", target, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('responseType', 'text/plain');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.send();
function process() {
console.log(xhr);
我希望得到 json 数据,但现在响应文本为空,并返回以下消息:
跨域读取阻塞 (CORB) 阻止了 MIME 类型为 application/json 的跨域响应 https://gitlab.com/api/v4/users/USER_ID/projects?callback=jQuery11130057655514217979986_1563975117007&_=1563975117008。详情请见https://www.chromestatus.com/feature/5629709824032768。
【问题讨论】:
标签: google-chrome http get xmlhttprequest gitlab-api