Reputation: 11
i am stuck here with a little jQuery Problem! I am using this code to load the content of a html file (bio.html) into a div containter (content). This works in IE8 and Firefox 6, but not in Google Chrome!
Any ideas what i might be doing wrong? Heres the Code:
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="./js/jquery.min.js"></script>
</head>
<div id="content">
hi
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#content').load('./html/bio.html');
});
</script>
Upvotes: 1
Views: 6709
Reputation: 13309
The issue is just that .load()
for local files is blocked by Chrome for security reasons. If you are using it on a server it works, given that all of the files originate from the same place.
To enable a working version locally, start Chrome with a command line flag enabled by trying:
In Mac OS X, quit Chrome, enter in Terminal:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
In Windows, quit Chrome, enter in Command Prompt:
chrome.exe --allow-file-access-from-files
(Maybe you actually have to have the path... I don't think so. If so, you'll have to find it yourself.)
In Linux, quit Chrome, enter something like this into the terminal:
/usr/bin/google-chrome --allow-file-access-from-files
Upvotes: 2
Reputation: 1085
Sounds like you are running this locally, is that correct? Chrome has some security features that prevent JQuery's load method to fail when run from a local harddrive. Try putting it on a server somewhere.
Upvotes: 1
Reputation: 8941
.load()
will not work in Chrome if you are loading files from your local system.
Putting it on a server will resolve the issue.
Upvotes: 1
Reputation: 50976
It works fine for me in chrome
http://sandbox.phpcode.eu/g/512ef/2
try to look at developer's inspect tool if you see any unexpected errors. Be sure you're in http:// or https:// protocol, file:// will not work
Upvotes: 1