問題描述
我在使用 IE11 和 ajax 時遇到了一個特殊錯誤.對于我使用下面的代碼發出的幾乎所有請求,一切都很好,但是當我嘗試與復制+粘貼方法結合使用時,它返回一個訪問被拒絕錯誤.總結一下
I'm having a peculiar error with IE11 and ajax. For nearly all the requests I make using the code below, everything is fine, yet when I try use in conjunction with a copy+paste method, it returns an Access is denied error. So to summarise
- 這段代碼在大多數瀏覽器中都能正常運行我編寫的所有函數
- 在 IE 11 + Windows 8.1 中,它在大多數情況下都有效,除非運行特定的復制和粘貼功能
- 有趣的是,當使用 IE 11,但使用不同的文檔模式(例如 8)時,我仍然收到相同的錯誤,即使它在 IE8 + Windows 7 中本機工作
- 錯誤是訪問被拒絕"
這里是 AJAX 代碼:
Here is the AJAX code:
function ajaxRequest(requestName,responseFunction,parameters) {
var xmlhttp;
if (requestName.length==0) return;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if(xmlhttp.responseText == 'Error') alert('Error processing request. Please refresh the page and try again');
else if(xmlhttp.responseText != '') eval(responseFunction+"('"+xmlhttp.responseText+"')");
}
}
var now = new Date();
var url = "control/ajax.php?request="+requestName+"¶meters="+parameters+"×tamp"+now;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
一個失敗的例子,設置了以下變量:
An example of a failure, had the following variables set:
請求名稱:save_marksheet_mark"響應函數:update_save_marksheet_mark"參數:[60962,1284,5]
requestName: "save_marksheet_mark" responseFunction: "update_save_marksheet_mark" parameters: [60962,1284,5]
這段代碼有問題嗎?在特定情況下,IE11 是否會在此代碼中引發錯誤?
Is there something wrong with this code? Is there a reason why IE11 would throw an error with this code, in particular circumstances?
推薦答案
這個問題似乎得到了很多關注,所以以防萬一有人想知道,我通過在原始 AJAX 上使用 setTimeout() 解決了這個問題稱呼.例如:
This question appears to be getting a lot of views, so just in case anybody was wondering, I solved this problem by using a setTimeout() on the original AJAX call. E.g:
setTimeout(function() {
ajaxRequest('save_mark','save_mark_completed',[60962,1284,5])
}, 1);
我假設這是 IE 中的某種錯誤.只需 1 毫秒!
I'm assuming it's some kind of bug in IE. Just 1 millisecond was all it needed!
這篇關于IE 11 錯誤 - 訪問被拒絕 - XMLHttpRequest的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!