0

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. It's working on FF, Chrome, Safari and other mobile browser.

Error Message - SEC7120 : Origin http://sub.example.com is not allowed by Access-Control-Allow-Origin.

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();

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

and navtive 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)

  • Can you also post the contents of the response header so we can make sure your PHP code is correctly setting the header? – Nate Kibler Aug 11 '14 at 16:12

2 Answers2

4

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.

AstroCB
  • 12,337
  • 20
  • 57
  • 73
Lionel
  • 1,949
  • 3
  • 17
  • 27
0

You may be facing an IE10 issue, and the ticket on JQuery has been closed as this is an issue with IE10 itself.

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.

Community
  • 1
  • 1
Mendhak
  • 8,194
  • 5
  • 47
  • 64