<input type="button" value="Load" id="load" />
<div id="file"></div>
$(document).ready(function(){
$('#load').click(function(){
$('#file').load('test.html',function(){
alert('File loaded');
});
});
});
它在Mozilla Firefox中正常运行...但是在chrome中,它给出了一个错误“ XMLHttpRequest无法加载file:/// D:/Tanveer%20Hussain/Jquery/test.html。收到无效响应。因此,源为'null'不允许访问”,在javscript控制台中...
问题只是出于安全原因,Chrome阻止了本地文件的.load()。如果您在服务器上使用它,因为所有文件都来自同一位置,因此它可以工作。
要在本地启用工作版本,请尝试:
在Mac OS X(相当Chrome)中,在Terminal中输入:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
在Windows(相当Chrome)中,在命令提示符下输入:
chrome.exe-允许从文件访问文件(也许您实际上必须具有路径...我不这样认为。如果是这样,则必须自己找到它。)
在Linux(相当Chrome)中,在终端中输入以下内容:
/usr/bin/google-chrome --allow-file-access-from-files
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句