jquery - CORS with JSON Fallback for IE -
i have following code works on browsers except ie: access denied. please help!!! have looked @ tons of examples , still cannot resolve this. keep simple doing returning text url.
<script type="text/javascript"> // insure document loaded... $(document).ready(function() { // set url pos api... var posapiurl = 'https://test.safety.com/posapi/getposmessage?app=rmis'; // load pos api message... function loadposmessage(edurl) { if (window.xmlhttprequest) { xmlhttp = new xmlhttprequest(); } else if (window.xdomainrequest) { xmlhttp = new xdomainrequest(); } else { xmlhttp = new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { var jsonedition = xmlhttp.responsetext; var objedition = json.parse(jsonedition); $.each(objedition, function(key, val) { if (val.length === 0) { $('.posmsgcontainer').hide(); } else { $('.posmsgcontainer').html(val); } }); } }; xmlhttp.open("get", edurl, true); xmlhttp.send(); } // make call load pos message... loadposmessage(posapiurl); }); </script>
the code above won't work because api ie's xdomainrequest different of xmlhttprequest. example, instead of onreadystatechange() uses onload().
i've found simplest way support cors on ie 8/9 include xhr-xdr-adapter.js file here: https://github.com/intuit/xhr-xdr-adapter/blob/master/src/xhr-xdr-adapter.js
you can include needed follows:
<!--[if lt ie 10]> <script src="xhr-xdr-adapter.js" type="text/javascript"></script> <![endif]-->
once include xhr-xdr-adapter, can use standard xmlhttprequest api, , not worry whether you're running on ie 8/9 or not (as long don't need fancy send custom headers, or use method other or post.)
Comments
Post a Comment