问题
Cant get this code to work in chrome, which is essential since I'm developing for android. Can anyone see the error?
I just want to load 'page1.html' into '#container1'. Should be easy and it was working before. But I have tried rebuilding the code from scratch and I can't see what the error is.
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TheTutorialBlog.com : jQuery Deep Linking</title>
<link href="css_elIndex.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.7.2.min.js"></script>
<script src="bbq-1.2.js"></script>
<script type="text/javascript">
$("document").ready(function(){
alert('doc ready');
$('#container1').load('page1.html');
});
</script>
</head>
<body>
<div class ="topBar">
<div class = "backButton">Home</div>
</div>
<div id="pageContainer">
<div class="pageViewer" id="container1">
</div>
<div class="pageViewer" id="container2">
</div>
<div class="pageViewer" id="container3">
</div>
</div>
</body>
</html>
Page1.html:
<ul class="tabs">
HEi
</ul>
回答1:
When accessing files via the local file system (file:// URLs) you cannot load any local AJAX resources in Chrome and Opera for security reasons.
When using HTTP there is the "same origin policy" to prevent sites from accessing data they shouldn't have access to. However, on the local file system there is no way to know what's safe to access and what not. So AJAX requests to local files are generally blocked.
来源:https://stackoverflow.com/questions/11281769/load-works-in-ie-and-dreamweaver-preview-but-no-opera-and-chrome