Ajax跨域请求COOKIE无法带上的解决办法
发布时间:2020-12-16 02:57:10 所属栏目:百科 来源:网络整理
导读:原生ajax请求方式: var xhr = new XMLHttpRequest(); xhr.open("POST","http://xxxx.com/demo/b/index.php",true); xhr.withCredentials = true; //支持跨域发送cookiesxhr.send(); jquery的ajax的post方法请求: $.ajax({ type: "POST",url: "http://xxx.c
原生ajax请求方式: var xhr = new XMLHttpRequest(); xhr.open("POST","http://xxxx.com/demo/b/index.php",true); xhr.withCredentials = true; //支持跨域发送cookies xhr.send(); jquery的ajax的post方法请求: $.ajax({ type: "POST",url: "http://xxx.com/api/test",dataType: ‘jsonp‘,xhrFields: { withCredentials: true },crossDomain: true, success:function(){ }, error:function(){ } }) 服务器端设置: header("Access-Control-Allow-Credentials: true"); header("Access-Control-Allow-Origin: http://www.xxx.com");转自:https://www.cnblogs.com/Hai--D/p/5083430.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- ruby-on-rails – Rails非表下拉列表
- xcode – 如何在Interface Builder中使用故事板时
- Cocos2d-x MenuItemToggle 实现开关按钮
- 最佳SQLite查询删除重复项
- AlamofireImage 使用 - swift加载网络图片,缩放
- SQLite创建触发器 CREATE TRIGGER
- ruby-on-rails – 升级到Rails 4.2问题
- c# – DataTable中的System.Data.DuplicateNameE
- ReactNative——UI5.ListView实现带标题的列表
- reactjs – React-router:通过路由传递数据
热点阅读