我在跨域方案中运行。 在登录期间,远程服务器返回Set-Cookie标头以及设置为true的Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding. The above example would fail if the header was wildcarded as: Access-Control-Allow-Origin: *。

对远程服务器的下一个ajax调用应该使用此cookie。

CORS的Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding. The above example would fail if the header was wildcarded as: Access-Control-Allow-Origin: *允许跨域日志记录。 有关示例,请查看[https://developer.mozilla.org/En/HTTP_access_control]。

对我来说,它似乎是JQuery中的一个错误(或者至少是下一版本中的功能)。

更新:

不会自动从AJAX响应中设置Cookie(引用:[http://aleembawany.com/2006/11/14/anatomy-of-a-well-designed-ajax-login-experience/)]

为什么?

您无法从响应中获取cookie的值以手动设置([http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-getresponseheader)]

我糊涂了..

应该有一种方法可以要求Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding. The above example would fail if the header was wildcarded as: Access-Control-Allow-Origin: *设置XMLHttpRequest.withCredentials = "true"参数。

回答:您应该使用[http://api.jquery.com/jQuery.ajax/]的Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding. The above example would fail if the header was wildcarded as: Access-Control-Allow-Origin: *参数

文档中的示例是:

$.ajax({

url: a_cross_domain_url,

xhrFields: {

withCredentials: true

}

});

服务器正确回答此请求也很重要。 在这里复制@Frédéric和@Pebbl的精彩评论:

Important note: when responding to a credentialed request, server must specify a domain, and cannot use wild carding. The above example would fail if the header was wildcarded as: Access-Control-Allow-Origin: *

所以当请求是:

Origin: http://foo.example

Cookie: pageAccess=2

服务器应该响应:

Access-Control-Allow-Origin: http://foo.example

Access-Control-Allow-Credentials: true

[payload]

否则,有效负载将不会返回到脚本。 请参阅:[https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials]

ajax传cookie,为什么jquery的.ajax()方法没有发送我的会话cookie?相关推荐

  1. ajax的同步,设置JQuery的Ajax方法同步

    如何设置jquery的ajax方法为同步 jax请求默认的都是异步的如果想同步 async设置为false就可以(默认是true) var html = $.ajax({  url: "so ...

  2. html ajax请求jsp,JSP+jquery使用ajax方式调用json的实现方法

    本文实例讲述了JSP+jQuery使用Ajax方式调用JSON的实现方法,在这里分享给大家以供大家参考,具体的实现以及代码如下所示: 前台: //test function test(uid) { i ...

  3. jquery ajax 不执行success,jQuery通过ajax方法获取json数据不执行success的原因及解决方法...

    1.jquery通过ajax方法获取json数据不执行success回调 问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准 ...

  4. java接口支持ajax,【JavaWeb】jQuery对Ajax的支持

    jQuery对Ajax的支持 jQuery对Ajax进行封装,提供了$.ajax()方法 语法:$.ajax(options) 常用设置项 说明 url 发送请求地址 type 请求类型get|pos ...

  5. html ajax访问不了,jquery 请求ajax失败或者不执行的原因是什么?

    开发中会经常用到Jquery中的ajax,配合Ashx处理程序,实现一些无刷新操作,有时候会出现一些问题,现在总结一下.有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助. jquery ...

  6. jquery ajax golang,原生和jQuery的ajax用法-Go语言中文社区

    form数据的序列化: $('#submit').click(function(){ $('#form').serialize(); //会根据input里面的name,把数据序列化成字符串:eg:n ...

  7. ajax.updater 返回值,jquery中Ajax.updater的等价物是什么?

    有使用一些方法阿贾克斯一样jQuery.ajax({...}) or $.ajax({...})除此之外还有它们的一些简化的版本太像: $.get()或jQuery.get() $.post()或jQ ...

  8. form通过ajax提交表单,Jquery通过Ajax方式来提交Form表单

    今天刚好看到Jquery的ajax提交数据到服务器的方法,原文是: 保存数据到服务器,成功时显示信息. jQuery 代码: $.ajax({ type: "POST", url: ...

  9. ajax parsererror报错,jQuery为ajax请求返回“ parsererror”

    我一直在从jquery收到针对Ajax请求的" parsererror",我尝试将POST更改为GET,以几种不同的方式(创建类等)返回数据,但我似乎无法弄清楚问题出在哪里. 我的 ...

最新文章

  1. MapReduce案例-wordcount-步骤分析
  2. Qt文档阅读笔记-Qt工作笔记-QTableWidget::selectedItems()官方解析与实例(如何进行多选)
  3. 【英语学习】【English L06】U05 Appointments L1 Can I book a taxi to the airport?
  4. Python re 模块深入探索
  5. 通用版程序在the new iPad与Xcode4.3中的不兼容。
  6. JSON跨域解决方案收集
  7. Centos7配置ThinkPHP5.0完整过程(二)
  8. Linux网络编程-TCPUDP测试工具下载和使用
  9. Matlab之聚类分析
  10. APISpace 银行卡二要素API 方便好用
  11. goahead文件下载
  12. 用PHP查看微信撤回的消息,[笔记]使用itchat监听微信撤回消息
  13. 微信小程序制作背景图片
  14. Cent OS (一)Cents OS的基本安装
  15. 值得一生珍藏的经典台词
  16. Web3:价值投资的范式转移
  17. python作图设置背景颜色_如何在matplotlib中设置绘图的外部背景颜色
  18. mysql联合索引如何创建
  19. 【Linux】Linux基础
  20. 2.2加勒比海盗船 最优装载问题

热门文章

  1. 基于ADSP-BF561的H.264视频编码器的实现
  2. elasticse报错 max virtual memory areas vm.max_map_count [65530] is too low, increase to at leas
  3. 美剧 silicon valley
  4. 机器人电焊电流电压怎么调_电焊电流的调节技巧
  5. 经济基础知识(初级)【6】
  6. 安全多方计算之隐私保护集合交集
  7. 汽车制造行业工厂数据、互联数据和移动数据存储解决方案
  8. 12.15有一种数叫回文数,正读和反读都一样,如12321便是一个回文数。编写一个程序,从命令行得到一个整数,判断该数是不是回文数
  9. 大唐“痴情”男女-白居易-湘灵
  10. 关于程序员的几个小段子