我是一个真正的noobie所以请原谅我的无知。
我们正在使用javascript ajax将html内容从另一个子域网页拉入(内容是动态html)。该脚本在Chrome,FF和IE 11中使用CORS可以正常工作。
在IE 8& 9(访问被拒绝)。我搜索和研究过,我看到我们可以在哪里使用XDomainRequest();当我们遇到IE 8& 9,但根本不知道如何实现它。
这是我们将作为http://sub1.domain.net/somepage.html的“请求”发送的示例代码:
<script type="text/javascript">
sendRequestFS('http://sub2.domain.net/aj-ad-display.php?type=fs&checkcat=2585&cid=-98113&heading=17263336&prid=20028557', 'fsad');
</script>
这是我们用来获取请求的ajax函数:
function createRequestObjectFS() { // alert ("CRQFS"); var returnObj = false; if(window.XMLHttpRequest) { returnObj = new XMLHttpRequest(); } else if(window.ActiveXObject) { try { returnObj = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { returnObj = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } return returnObj; } var httpFS = createRequestObjectFS(); var targetFS; // This is the function to call, give it the script file you want to run and // the div you want it to output to. function sendRequestFS(scriptFileFS, targetElementFS) { // alert ("RQFS File: " + scriptFileFS + " Target : " + targetElementFS); targetFS = targetElementFS; try{ httpFS.open('get', scriptFileFS, true); } catch (e){ document.getElementById(targetFS).innerHTML = e; return; } httpFS.onreadystatechange = handleResponseFS; httpFS.send(); } function handleResponseFS() { if(httpFS.readyState == 4) { try{ // alert ("HRQFS"); var strResponseFS = httpFS.responseText; document.getElementById(targetFS).innerHTML = strResponseFS; } catch (e){ document.getElementById(targetFS).innerHTML = e; } } }
所以 - 问题是..我们怎样才能让这个在IE 8&amp; amp; 9? 老实说,我不太了解这一点 - 我通常会找到一个有效的脚本,尝试剖析元素以了解该工作的方式,然后将它们更改为我需要的...所以现实代码最有帮助 - 或者示例代码使用此代码添加了我们需要使其工作的内容。
感谢。