jQuery .load() 在 Chrome 中不起作用 [英] jQuery .load() not working in Chrome
问题描述
.load()
工作正常,但由于某种原因它现在不在 Chrome 中(大概是某种更新).我在 Chrome 5.0.375.55 上.我已将此问题隔离为:
.load()
was working fine, but for some reason it's not in Chrome now (presumably some kind of update). I'm on Chrome 5.0.375.55. I've isolated the problem to this:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#reader').load('test.htm');
});
</script>
</head>
<body>
<div id='reader'>Loading ...</div>
</body>
</html>
test.htm
<h1>Loaded successfully</h1>
这在 Firefox 和 IE 上有效,但在 Chrome 上它会用空替换 #reader
div 的内容.
This works on Firefox and IE, but on Chrome it replaces the contents of the #reader
div with nothing.
我应该补充一点,我在本地运行它,它永远不会部署在网络服务器上.
I should add that I'm running this locally, and it's never going to be deployed on a web server.
Edit2: 我试过 .load('file:///C:/path/to/test.htm')
,它在 FF 中工作但不铬.
I've tried .load('file:///C:/path/to/test.htm')
which works in FF but not Chrome.
推荐答案
这是 Chrome 解释的同源策略"(或具有相同效果的错误).尝试使用 --allow-file-access-from-files
运行 Chrome.
It's the "same origin policy" as interpreted by Chrome (or a bug with the same effect). Try running Chrome with --allow-file-access-from-files
.
这篇关于jQuery .load() 在 Chrome 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!