Javascript – SCRIPT5 : Access denied error on ie with XMLHttpRequest

internet-explorer-9javascriptxmlhttprequest

I've got a SCRIPT5 error with an XMLHttpRequest and I can't fix the problem even with this question : SCRIPT5: Access is denied in IE9 on xmlhttprequest

Here's my code :

function getXDomainRequest()
{
        var xdr = null;

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
    xdr=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
    xdr=new ActiveXObject("Microsoft.XMLHTTP");
  }
        return xdr;        
}

function sendData()
{
        var xdr = getXDomainRequest();
        xdr.onload = function() 
        {
                var xml = xdr.responseXML; 
                var prod = xml.documentElement.getElementsByTagName("produit");          
        }
        xdr.open("GET", "http://www.mysite.tm.fr/page.php?var1="+ var1 +"");
        xdr.send();
}

Any help will be very very very appreciated!

Precision : The distant website returns me an XML content like this :

<liste>
<produits>
<produit>...</produit>
<produit>...</produit>
<produit>...</produit>
</produits>
</liste>

Best Answer

IE9 doesn't support CORS for XHR. IE10 will. Source.

However, IE8/9 supports CORS with XDomainRequest.