IE 11错误 - 访问被拒绝 - XMLHttpRequest [英] IE 11 error - Access is denied - XMLHttpRequest

查看:1107
本文介绍了IE 11错误 - 访问被拒绝 - XMLHttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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


  • 此代码在大多数浏览器中对我编写的所有函数都有效。

  • In IE 11 + Windows 8.1,它在大多数情况下都有效,除非在运行特定的复制和粘贴功能时

  • 有趣的是,当使用IE 11时,但是使用不同的文档模式如8,我仍然会得到相同的错误,即使它在IE8 + Windows 7中本地工作

  • 错误是'访问被拒绝'

  • This code works normally in most browsers for all functions I have written
  • In IE 11 + Windows 8.1, it works in most cases, except when running a particular copy and paste function
  • Interestingly, when using IE 11, but with a different Document mode such as 8, I still get the same error, even though it works natively in IE8 + Windows 7
  • The error is 'Access is denied'

这是AJAX代码:

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+"&parameters="+parameters+"&timestamp"+now;
 xmlhttp.open("GET",url,true);
 xmlhttp.send();
}

失败的一个例子,设置了以下变量:

An example of a failure, had the following variables set:

requestName:save_marksheet_mark
responseFunction: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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆