Dre*_*rew 25 jquery cors internet-explorer-11
我有一个CORS(跨源资源共享)请求从我的登录页面到应用程序站点,在不同的URL上.我有一个简单的页面我ping以确定用户是否已经登录,如果是,则重定向它们.否则我会显示一个登录页面.我使用jQuery.
这适用于safari,chrome,firefox ......而不是IE(自然).根据MS,IE 10及更高版本应该使用withCredentials支持CORS请求
我正在使用jquery-2.0.3.min.js
任何想法为什么这不适用于IE11?
编辑:它似乎部分工作,因为它现在返回值{"id":false}.每次都会发生这种情况,这意味着服务器永远不会获得凭据.我也发布了我的is_logged_in页面,我正在使用代码点火器框架.
编辑:在IE的安全设置下启用"允许跨域的数据源"后,我不再收到任何错误消息.
我收到的确切错误是:
SEC7118:用于http://mysite.net/guest/is_logged_in的 XMLHttpRequest 需要跨源资源共享(CORS).
$.ajax({
url: 'http://mysite.net/guest/is_logged_in',
type: 'POST',
crossDomain: true,
xhrFields: {
withCredentials: true
},
dataType: 'json',
success: function(data) {
if(data.id) {
window.location.replace("http://mysite.net");
}
}
});
Run Code Online (Sandbox Code Playgroud)
和
public function is_logged_in()
{
$allowed = array(
'http://mysite.net',
'http://www.mysite.net',
'http://www.mysite.com',
);
$url = $_SERVER['HTTP_REFERER'];
$url = substr($url, 0, strpos($url, '/', 8));
if(isset($_SERVER['HTTP_ORIGIN']))
{
if(in_array($_SERVER['HTTP_ORIGIN'], $allowed))
{
$this->output->set_header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
}
}
else
{
if(in_array($url, $allowed))
{
$this->output->set_header('Access-Control-Allow-Origin: ' . $url);
}
}
$this->output->set_header('Access-Control-Allow-Headers: X-Requested-With');
$this->output->set_header('Access-Control-Allow-Credentials: true');
$this->output->set_header("Access-Control-Expose-Headers: Access-Control-Allow-Origin");
//TODO: Try to detect if this is an ajax request, and disallow it if not.
$data = new stdClass();
$this->load->library("ion_auth");
if($this->ion_auth->logged_in())
{
$data->name = $this->ion_auth->user()->row()->first_name;
$data->id = $this->ion_auth->get_user_id();
} else {
$data->id = false;
}
$this->output->set_output(json_encode($data));
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
Eri*_*Law 18
将"跨域访问数据源"的设置更改为"已启用"将关闭IE中的跨域检查,并且非常不安全.相反,您需要确保目标第三方资源发送有效的P3P策略,该策略指示它不会对用户的隐私做出可怕的事情.
Dre*_*rew 13
发现了这个问题.
我有一个类似的问题(一般使用CORS,而不是特别是GWT).事实证明,浏览器设置阻止了第三方cookie(IE10> Internet选项>隐私>高级>第三方Cookie>接受).为了解决这个问题,我检查了"覆盖自动cookie处理","接受"(第三方Cookie)和"始终允许会话cookie".
Andrew在这里回答了这个问题:CORS在IE10中不适用于cookie
编辑:(现在我知道要搜索什么)这个问题可能会产生一些帮助,如果其他人遇到这个问题.Internet Explorer 10忽略XMLHttpRequest'xhr.withCredentials = true'
我们遇到的问题是,除了所有其他浏览器,IE11 都Access-Control-Request-Headers: accept随请求一起发送,因此必须将“accept”添加到 allowedHeaders cors 配置中,因为它似乎不是默认 spring cors 配置的一部分。
| 归档时间: |
|
| 查看次数: |
70975 次 |
| 最近记录: |