XMLHttpRequest无法加载file:/// C:/Users/hamma/Desktop/rao.html [英] XMLHttpRequest cannot load file:///C:/Users/hamma/Desktop/rao.html

查看:9557
本文介绍了XMLHttpRequest无法加载file:/// C:/Users/hamma/Desktop/rao.html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <!DOCTYPE html> 
< html>
< head>
< script src =jquery-2.1.4.js>< / script>
< script>
$(document).ready(function(){
$(button)。click(function(){
$(#div1)。load(rao.txt );
});
});
< / script>
< / head>
< body>

< div id =div1>< h2>让jQuery AJAX更改此文本< / h2>< / div>

< button>获取外部内容< / button>

< / body>
< / html>

我想用一些文本或其他网页更改div1的内容,而无需重新加载默认页面。



在控制台中收到以下错误消息:
$ b


XMLHttpRequest无法加载文件:/// C:/Users/hamma/Desktop/rao.html。交叉原始请求仅支持协议模式:http,data,chrome,chrome-extension,https,chrome-extension-resource。


解决方案

根据您的控制台输出:


XMLHttpRequest无法加载file:/// C:/用户/汉玛/桌面/ rao.html。只有协议方案支持跨源请求:http,data,chrome,chrome-extension,https,chrome-extension-resource。

这意味着你正试图运行没有服务器的文件,例如 file:/// [...] ,出于安全原因,你不能运行AJAX请求



您需要设置服务器并通过该页面运行该页面以发送请求。



更多帮助



如果您使用的是Chrome,请尝试



同源政策



CORS


<!DOCTYPE html>
<html>
<head>
<script src="jquery-2.1.4.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#div1").load("rao.txt");
    });
});
</script>
</head>
<body>

<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>

<button>Get External Content</button>

</body>
</html>

i want to change the content of div1 with some text or some other webpage without reloading the default page.

I get the following error message in the console:

XMLHttpRequest cannot load file:///C:/Users/hamma/Desktop/rao.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

解决方案

According to your console output:

XMLHttpRequest cannot load file:///C:/Users/hamma/Desktop/rao.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

That means that you are trying to run the file without a server i.e. file:///[...] and for security reasons you can't run AJAX requests like that.

You need to setup a server and run the page through that to send requests.

More Help

If you are using Chrome, try this.

Reading Material

Same-Origin-Policy

CORS

这篇关于XMLHttpRequest无法加载file:/// C:/Users/hamma/Desktop/rao.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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