简体   繁体   English

跨域AJAX请求不适用于IE10

[英]Cross Domain AJAX Request is not working on IE10

I sent ajax request from 'sub.example.com' to 'www.example.com/api/lists'(yes, it is subdomain), but it's not working only IE. 我从“ sub.example.com”向“ www.example.com/api/lists”发送了ajax请求(是的,它是子域),但它不仅在IE中起作用。 It's working on FF, Chrome, Safari and other mobile browser. 它可以在FF,Chrome,Safari和其他移动浏览器上运行。

Error Message - SEC7120 : Origin http://sub.example.com is not allowed by Access-Control-Allow-Origin. 错误消息-SEC7120:Access-Control-Allow-Origin不允许使用来源http://sub.example.com

My server setting is 我的服务器设置是

<?php
  header('Access-Control-Allow-Origin : *');
  header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');

I tried two ways. 我尝试了两种方法。 first, jQuery.ajax(); 首先,jQuery.ajax();

$.ajax({
  url : 'http://www.example.com/api/lists',
  type : 'GET',
  dataType : 'JSON',
  cache : false,
  crossDomain : true
}).success(function(data){
  // do something
});

and navtive javascript. 和实用的javascript。

 var xhr = new XMLHttpRequest();
 xhr.open('GET', 'http://www.example.com/api/lists');
 xhr.send();

both of them not working only IE10 Browser.(not tested lt IE10 yet) 它们都不能仅在IE10浏览器上运行。(尚未测试IE10)

Remove the space between the colon and the asterisk. 删除冒号和星号之间的空间。

Change 更改

header('Access-Control-Allow-Origin : *');

to

header('Access-Control-Allow-Origin: *');

Internet Explorer is quite unflexible when it comes to correct syntax. 对于正确的语法,Internet Explorer非常不灵活。

You may be facing an IE10 issue , and the ticket on JQuery has been closed as this is an issue with IE10 itself. 您可能会遇到IE10问题 ,并且JQuery上的票证已关闭,因为这是IE10本身的问题。

The 'workaround' at the moment is to set compatibility mode: 目前的“解决方法”是设置兼容模式:

<meta http-equiv="x-ua-compatible" content="IE=9" >

It is also worth reading through the post I've linked to. 还值得阅读我链接到的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM