Refused to set unsafe header “Cookie” with ajax call Rest server

岁酱吖の 提交于 2020-01-21 03:37:21

问题


Im busy building a Phonegap app that connects with my Drupal rest server (Module: Services). My Drupal website (PHP) has the code: header('Access-Control-Allow-Origin: *');

When I'm trying to connect to my Rest server with the following code: http://pastebin.com/xfygQexn I'm getting the following console message: Refused to set unsafe header "Cookie"

Code: http://pastebin.com/FNGgPQKv Error: Refused to set unsafe header "Cookie"

Is anyone familiar with this problem?

Many thanks.

Im needing the token and the session for a logout call.


回答1:


You are trying to set cookies for separate ajax call but this is not allowed by XMLHttpRequest specification. Instead, you can set a cookie to the current page and browser will put it in your ajax request if domain/path matches, i.e. by using jquery.cookie plugin:

$.cookie('the_cookie', 'the_value', { path: '/' });


来源:https://stackoverflow.com/questions/21005391/refused-to-set-unsafe-header-cookie-with-ajax-call-rest-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!