【问题标题】:jquery ajax bad_url error on local machine in same parent folder同一父文件夹中本地计算机上的 jquery ajax bad_url 错误
【发布时间】:2015-12-24 16:30:06
【问题描述】:

刚开始学习jQuery,所以对错误等深层机制不太了解。

我正在使用 jQuery 解析 html 页面的 xml 文件,我的文件夹结构按以下方式构建

客户

   -CurrentFiles
     -test.xml
   -stations
     -test.html

我正在使用 Google 的 jQuery cdn 来加载 jQuery 库。

这是我的代码

 <script type="text/javascript">
    var data = [];
        $(document).ready(function () {
           $.ajax({
               type:'post',        //just for ECHO
               dataType: "xml", // type of file you are trying to read
               url: './../CurrentFiles/test.xml', // name of file you want to parse
               success: parse, // name of the function to call upon success
               async:    false,
               error: function(xhr, status, error) { 
                   alert("error");

                   console.log(error);
                   console.log(status);
               }
           });

           function parse(xmldata) {
               $(xmldata).find("value").each(function(){
                   alert($(this).text());
                   data.push($(this).text());
               });
           }
               console.log("data array:" + data);
        });

    </script>

xml文件格式如下

<?xml version="1.0" encoding="utf-8"?>
<values>     
  <value date="2015-07-12">37.170</value>
  <value date="2015-07-13">7.190</value>
  <value date="2015-07-12">37.170</value>
  <value date="2015-07-12">3.210</value>
  <value date="2015-07-12">37.20</value>

我得到的错误是

DOMException [NS_ERROR_DOM_BAD_URI:“访问受限 URI 被拒绝”
代码:1012
nsresult:0x805303f4
地点:https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js:4]

我真的不明白这个错误是在我这边,文件不能有写权限还是在处理 CDN?

顺便说一句,我使用的是Firefox。

【问题讨论】:

    标签: jquery ajax firefox


    【解决方案1】:

    你可以通过修改安全权限在FF3本地开发。您可以按照以下步骤执行此操作:

    Type about:config into the Location Bar (address bar) and press Enter
    Click the “I’ll be careful, I promise” button
    Change the security.fileuri.strict_origin_policy:
    

    是的 本地文档可以访问同一目录和子目录中的其他本地文档,但不能访问目录列表。 (默认)

    错误 本地文档可以访问所有其他本地文档,包括目录列表。

    【讨论】:

      猜你喜欢
      • 2011-02-16
      • 2012-01-12
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      相关资源
      最近更新 更多