拒绝设置不安全的头部“Cookie"使用 ajax 调用 Rest 服务器 [英] Refused to set unsafe header "Cookie" with ajax call Rest server

查看:31
本文介绍了拒绝设置不安全的头部“Cookie"使用 ajax 调用 Rest 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在忙于构建一个与我的 Drupal 休息服务器(模块:服务)连接的 Phonegap 应用程序.我的 Drupal 网站 (PHP) 有代码: header('Access-Control-Allow-Origin: *');

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: *');

当我尝试使用以下代码连接到我的 Rest 服务器时:http://pastebin.com/xfygQexn 我收到以下控制台消息:拒绝设置不安全的标题Cookie"

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"

代码:http://pastebin.com/FNGgPQKv错误:拒绝设置不安全的标题Cookie"

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

有人熟悉这个问题吗?

非常感谢.

我需要令牌和会话以进行注销调用.

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

推荐答案

您正在尝试为单独的 ajax 调用设置 cookie,但 XMLHttpRequest 规范.相反,您可以为当前页面设置一个 cookie,如果域/路径匹配,浏览器会将其放入您的 ajax 请求中,即使用 jquery.cookie 插件:

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: '/' });

这篇关于拒绝设置不安全的头部“Cookie"使用 ajax 调用 Rest 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆