JavaScript错误"拒绝访问"在Internet explorer中

JavaScript error "Access is denied" in internet explorer

本文关键字:quot explorer Internet JavaScript 拒绝访问 错误      更新时间:2023-09-26

当我在IE中运行我的网页时(代码在其他浏览器中运行良好),我得到这个错误。

这是HTML代码:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<--- some html code --->
<iframe src='http://localhost/page1.php' style="background: transparent; overflow: hidden; height: 210px; width: 390px;" frameborder="0"  />
</body>
</html>

这是page1.php

<!DOCTYPE html>
<html>
<body>
<form action="usercheck.php" method="POST">
USERNAME:<input name="uname" id="uname" type="text" maxlength="12" required/>
<input type="submit" value="Submit">
</form>
</body>
</html>

这是usercheck.php

<?php
//some php code    
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<--- some html code --->
</body>
</html>

问题是,当到达usercheck.php后点击提交按钮在page1.php我得到错误http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js. Access is denied.这是一个错误的图像:https://i.stack.imgur.com/diCoF.jpg。然后,我得到的错误,'$'符号没有定义(这是由于未能加载jquery库)。

编辑-我已经尝试包括jquery文件在我的服务器,但仍然是错误的到来。我还为usercheck.php尝试了以下代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
/*! jQuery v1.10.1 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery.min.map
//and the rest of the jquery library...
</script>
</head>
<body>
<--- some html code --->
</body>
</html>

我这次得到的错误是:https://i.stack.imgur.com/hR9aN.jpg (usercheck2.php的原始名称是rscheck.php在我的服务器)。然后,我得到的错误,'$'符号没有定义(这是由于未能加载jquery库)。如果我直接打开page1.php的内容(通过url- localhost/page1.php),那么一切都可以正常工作。

这是我使用JQuery的唯一代码:

if($("#pret").contents().text().search("NAMECHECK: NOTAVALIBLE")!=-1)

我可以排除jquery只有当我可以将此代码转换为javascript

这是一个合法的jQuery 1.10.1错误:http://bugs.jquery.com/ticket/13980 .
使用jQuery 1.10.01.10.2,错误不再发生

尝试下载jquery.min.js到您的服务器并从那里包含它。例如:

<script type="text/javascript" src="/jquery.min.js"></script> .

看起来internet explorer无法访问资源:将其下载到您自己的服务器可能会解决这个问题。

这是我的问题的有效解决方案。我想要jquery的原因是我想运行这段代码:

if($("#pret").contents().text().search("NAMECHECK: NOTAVALIBLE")!=-1)

我删除了jquery库,并使用这个javascript做同样的事情:

var n=document.getElementById("pret").innerHTML.search("NAMECHECK: NOTAVALIBLE");
if(n != -1)

现在页面上没有错误,我可以做我想做的。所以这个错误是由于jquery库无法在网页中加载而导致的。但我不知道为什么即使下载jquery库在我的服务器我得到同样的错误ie。'访问被拒绝'.

原因在iframe。当jQuery从外部主机加载到iframe时,每次当您试图在主/外部html文件中使用任何jQuery函数时,IE都会出于安全原因抛出错误。

1)上传jQuery到您的服务器,

2)或者只包含在主html文件中(不包含在iframe中)