【发布时间】:2014-02-18 13:29:42
【问题描述】:
我提到我阅读了建议的链接......并且无法理解 建议..”使用 Greasemonkey 修改 Pages 并开始写一些 javascript修改网页
我正在加载一个带有$.ajax 的文本文件。在 Firefox 上运行代码时,出现以下错误:
错误:[“访问受限 URI 被拒绝”代码:“1012”nsresult:“0x805303f4 (NS_ERROR_DOM_BAD_URI)”位置:“
”]
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
$.ajax({ url: "demo_test.txt",
success: function (result) {
$("#div1").html(result);
},
error: function (abc) {
alert(abc.statusText);
},
cache:false
});
return false;
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
我已经阅读了以下问题:
- firefox reading web page from local JS file -- access to restricted URI denied, code: 1012, nsresult: NS_ERROR_DOM_BAD_URI
- Error: [Exception... "Access to restricted URI denied" .... while calling $.ajax method
有人建议不要使用文件系统,所以把网址改成http://demo_test.txt,但还是没有解决问题。
我还听说可能是因为跨域问题。如果是这样,那究竟是什么意思,我应该如何解决这个问题?
【问题讨论】:
-
您是否正在使用 filr 协议...又名
c:\\test\foo.htmlgithub.com/mrdoob/three.js/wiki/How-to-run-things-locally -
我想我不是。根据您的链接,我做了以下操作: 1. 将 url 更改为“D:\\demo_test.txt” 2. 更改 Firefox 中的本地文件安全策略。但它仍然给我同样的错误
-
你是在本地服务器上运行吗....又名
http://localhost或者你只是点击一个文件,它会在浏览器中打开。 -
我点击 HTML 文件。它在 FireFox 中打开,地址为“file:///C:/Users/Administrator/Desktop/New%20folder/my_html.html”
-
您在本地文件协议上运行。您需要启用 Firefox 才能访问文件,就像我在第一条评论中发布的链接告诉您的那样。你真的应该在本地运行 IIS 或 Apache 而不必处理这个问题。
标签: javascript jquery ajax