相关疑难解决方法(0)

XMLHttpRequest Origin null不允许Access-Control-Allow-Origin for file:/// to file:///(Serverless)

我正在尝试创建一个可以下载并通过启动其索引文件在本地运行的网站.

所有文件都是本地的,没有资源在线使用.

当我尝试使用jQuery的AJAXSLT插件来处理带有XSL模板的XML文件时(在子目录中),我收到以下错误:

XMLHttpRequest cannot load file:///C:/path/to/XSL%20Website/data/home.xml. Origin null is not allowed by Access-Control-Allow-Origin.

XMLHttpRequest cannot load file:///C:/path/to/XSL%20Website/assets/xsl/main.xsl. Origin null is not allowed by Access-Control-Allow-Origin.

发出请求的索引文件是file:///C:/path/to/XSL%20Website/index.html在存储使用的JavaScript文件时file:///C:/path/to/XSL%20Website/assets/js/.

我该怎么做才能解决这个问题?

xml xslt jquery xmlhttprequest cors

206
推荐指数
4
解决办法
26万
查看次数

AJAX GET 无法处理本地 JSON 文件?

我有一个 JSONP URL,它正在提取数据并刚刚切换到本地 JSON 文件,现在我收到错误。我不明白为什么它不能使用本地 JSON 文件?

<script type="text/javascript">
    $.ajax({
        type : 'GET',
        dataType : 'json',
        url: '/json/topics.json',
        success : function(data) {
            console.log(data); 
            var topics = [];
            $.each(data.results, function(index, obj){
                topics.push({
                    username: obj.TopicName,
                    mentions: obj.LastHourCount,
                    totalcount: obj.TotalCount,
                    daycount: obj.Last24HoursCount
                }); 
            });
            $('#leader').tmpl(topics).appendTo('#top3');
        } 
    });
</script>
Run Code Online (Sandbox Code Playgroud)

在控制台中,由于某种原因,它说 AJAX 是一个匿名函数?有什么建议么?

ajax jquery local-files

5
推荐指数
1
解决办法
4万
查看次数

标签 统计

jquery ×2

ajax ×1

cors ×1

local-files ×1

xml ×1

xmlhttprequest ×1

xslt ×1