Use CORS for REST API via XDomain proxy in IE8, IE9 for JavaScript/Angular

Because Internet Explorer 8 and 9 don’t support CORS properly (no custom headers such as an API key, only GET/POST, etc.) you may have problems using a modern REST API. However Jaime Pillora came up with a great solution called XDomain which acts as a pure JavaScript proxy for your API calls to get around CORS. This will only work if you have control over both the API you’re consuming and the JavaScript application.

Put this page in the web root of your API…

All you need to do to get this setup is to make sure you include it before any other JavaScript (such as Angular or jQuery) that will use IE’s XDomainRequest, as it will act as a drop-in replacement for it.

Your application would then look something like this…

Using BrowserStack or with the (limited) IE developer tools you will either see some debug messages from XDomain, or if you see “Access Denied” it will be because XDomain can’t connect to your proxy page (check the http/https protocols match and that the page is accessible on your API from where your JavaScript application is hosted)

Add comment