Cross Domain AJAX Works with IE All Version + Chrome + Firefox

  1. <script type="text/javascript">  
  2. function isIE()  
  3. {  
  4.     var myNav = navigator.userAgent.toLowerCase();  
  5.     return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false;  
  6. }  
  7. jQuery(window).load(function()  
  8. {  
  9.     if (isIE() <= 9 && window.XDomainRequest)  
  10.     {  
  11.         if (window.XDomainRequest)  
  12.         {  
  13.             var xdr = new XDomainRequest();  
  14.             var query = "URL";  
  15.             if (xdr)  
  16.             {  
  17.                 xdr.onload = function()  
  18.                 {  
  19.                     alert(xdr.responseText);  
  20.                 }  
  21.                 xdr.onerror = function()  
  22.                 { /* error handling here */ }  
  23.                 xdr.open('GET', query);  
  24.                 xdr.send();  
  25.             }  
  26.         }  
  27.     }  
  28.     else  
  29.     {  
  30.         jQuery.ajax(  
  31.         {  
  32.             type: "GET",  
  33.             crossDomain: true,  
  34.             url: "URL",  
  35.             dataType: "json",  
  36.             success: function(data)  
  37.             {  
  38.                 alert("Success");  
  39.             },  
  40.             error: function(response, textStatus, errorThrown)  
  41.             {  
  42.                 alert('not OK ' + response.responseText);  
  43.                 alert('not OK ' + textStatus.responseText);  
  44.                 alert('not OK ' + errorThrown);  
  45.             }  
  46.         });  
  47.     }  
  48. });  
  49. </script>