XMLHttpRequest无法加载file:/// C:/Users/hamma/Desktop/rao.html
$(document).ready(function(){ $("button").click(function(){ $("#div1").load("rao.txt"); }); }); Let jQuery AJAX Change This Text
我想用一些文本或其他网页更改div1的内容,而无需重新加载默认页面。
我在控制台中收到以下错误消息:
XMLHttpRequest无法加载file:/// C:/Users/hamma/Desktop/rao.html。 交叉源请求仅支持协议方案:http,数据,chrome,chrome-extension,https,chrome-extension-resource。
根据你的控制台输出:
XMLHttpRequest无法加载file:/// C:/Users/hamma/Desktop/rao.html。 交叉源请求仅支持协议方案:http,数据,chrome,chrome-extension,https,chrome-extension-resource。
这意味着您尝试在没有服务器的情况下运行文件,即file:///[...]
,出于安全考虑,您无法运行这样的AJAX请求。
您需要设置服务器并运行该页面以发送请求。
更多帮助
如果您使用的是Chrome,请尝试使用此function 。
阅读材料
同源-政策
CORS
将文件“rao.txt”复制到项目文件夹中。 设置本地服务器。 使用wamp / xamp设置localserver。 访问http://localhost/project_folder/path_to_rao.txt
等文件