解决跨域 ajax 请求 服务器端 session 不能保存问题

来源:互联网 发布:松下机器人示教编程 编辑:程序博客网 时间:2024/06/05 10:30

解决方案

服务器端设置header头

// 以下是php代码$aAllowList = [    'http://123.com','http://456.com'];if(in_array(ORIGIN, $aAllowList)){    header('Access-Control-Allow-Origin:'.ORIGIN );    header("Access-Control-Allow-Credentials: true" );}

前端 get/post 加入如下参数

$.ajax({      url: url,      type: 'GET',      crossDomain: true,      xhrFields: {            withCredentials: true      },      success: function(){}})
0 0