为什么跨域请求返回错误“显示临时标头”?

时间:2018-07-11 21:15:20

标签: javascript django cookies xmlhttprequest cross-domain-policy

我在angular6上有前端(http://localhost:4200),在django1.8上有后端(http://127.0.0.1:8000)。在后端,我的视图如下所示:

def display_form(request):
        response = HttpResponse('set csrf cookie for form')
        rotate_token(request)
        response['Access-Control-Allow-Origin'] = 'http://localhost:4200/login'
        response['Access-Control-Allow-Credentials'] = 'true'
        response['Access-Control-Allow-Headers'] = 'X-CSRF-TOKEN'
        return response 

在前端,我的请求函数如下所示:

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.open('GET', Config.host + 'users/display_form', true);
xhr.onload = function() {
  console.log( 'xhr req ok' + xhr.status + xhr.statusText + xhr.responseText);
}
xhr.onerror = function() {
  console.log( 'Ошибка ' + this + xhr.status + xhr.statusText + xhr.responseText);
  console.dir(this);
}
xhr.send();  

但是在发送xhr请求后,我在chrome网络标签中收到以下错误消息。

enter image description here

我需要成功进行跨域请求,并将cookie设置为浏览器cookie存储。请帮助我。

PS: 如果我使用this chrome扩展名,则请求成功

0 个答案:

没有答案
相关问题