extjs和yii跨域问题解决
Extjs
只是跨域extjs并不需要特别的设置,但是默认并不支持cookie会话
app.js顶部加入
Ext.Ajax.setWithCredentials(true);
这项只能解决通过Ext.Ajax发起请求时发送Cookie的问题,proxy还要单独处理
要让proxy ajax默认发送cookie需要overrides Ext.data.proxy.Ajax,在overrides\data\proxy目录中创建Ajax.js,内容为
Ext.define('overrides.data.proxy.Ajax', {
override:'Ext.data.proxy.Ajax',
config: {
/**
* @cfg {Boolean} withCredentials
* This configuration is sometimes necessary when using cross-origin resource sharing.
* @accessor
*/
withCredentials: true
}
});
YII
index.php或controller中加入以下语句
if(isset($_SERVER['HTTP_ORIGIN']))
{
//$_SERVER['HTTP_X_REQUESTED_WITH']="XMLHttpRequest";
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header("Access-Control-Allow-Credentials: true");
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
{
if(isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']}");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
header('Access-Control-Max-Age: 86400');
//header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
//header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie, Authorization');
//header('Access-Control-Expose-Headers','Set-Cookie');
webapp()->end();
return;
}
相关推荐
SXIAOYI 2020-09-16
有心就有方向 2012-09-03
zfyaixue 2013-06-14
pigsmall 2020-11-19
Ladyseven 2020-07-25
whileinsist 2020-06-24
gufudhn 2020-06-12
冰蝶 2020-06-05
LinuxAndroidAI 2020-06-04
supperme 2020-05-28
yaodilu 2020-05-10
e度空间 2020-04-27
云端漂移 2020-04-09
peterwzc 2020-03-17
ebuild 2013-05-14
donghedonghe 2013-05-31
tdeclipse 2011-02-28
linuxprobe0 2013-04-15