通过加载AJAX的文本文件给出的限制URI错误 [英] Loading a text file through AJAX gives restricted URI error

查看:122
本文介绍了通过加载AJAX的文本文件给出的限制URI错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提到我读建议的链接...并不能看得懂的   建议..使用Greasemonkey的修改页面,并开始编写一些   JavaScript来修改网页

I mentioned i read the suggested link ...and Could not able to understand the suggestion .."Use Greasemonkey to modify Pages and start writing some javascript to modify a web page

我加载与 $的文本文件。AJAX 。当运行在Firefox上的code,我得到以下错误:

I am loading a text file with $.ajax. When running the code on Firefox, I get the following error:

错误:[访问受限制的URI被拒绝code:1012nsresult:0x805303f4(NS_ERROR_DOM_BAD_URI)的位置:<未知>中]

Error: ["Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "<unknown>"]

下面是我的code:

<!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>

我已经阅读了以下几个问题:

I've already read the following questions:

  • <一个href="http://stackoverflow.com/questions/2666839/firefox-reading-web-page-from-local-js-file-access-to-restricted-uri-denied">firefox从本地JS文件中读取网页 - 访问受限制的URI被拒绝,code:1012,nsresult:NS_ERROR_DOM_BAD_URI
  • <一个href="http://stackoverflow.com/questions/1758183/error-exception-access-to-restricted-uri-denied-while-calling-ajax?rq=1">Error: [异常...&QUOT;访问受限制的URI否认&QUOT; ....同时呼吁$就法
  • 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 ,但是这并没有解决的问题。

It was suggested that file system should not be used, so changed the URL to http://demo_test.txt, but that did not solve the issue.

我还听说,这可能是因为跨域的问题。如果是的话,究竟是由意思,我应该怎么解决这个问题?

I also heard that it might be because of a cross domain issue. If so, what exactly is meant by that, and how should I solve the problem?

推荐答案

浏览器安全$ P $运行pvents的code。你最好运行的本地服务器,如IIS或Apache。

Browser security prevents the code from running. You are better off running a local server such as IIS or Apache.

您可以更改您的浏览器通过改变浏览器的配置来运行本地内容

You can change your browser to run local content by changing a browser config

火狐

  1. 进入about:config中
  2. 找到security.fileuri.strict_origin_policy参数
  3. 将其设置为false

这篇关于通过加载AJAX的文本文件给出的限制URI错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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