jQuery load()代码在Google Chrome中不起作用 [英] jQuery load() code not working in Google Chrome

查看:94
本文介绍了jQuery load()代码在Google Chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个jQuery问题!我正在使用此代码将html文件(bio.html)的内容加载到div容器(内容)中.这在IE8和Firefox 6中有效,但在Google Chrome中不起作用!

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>

推荐答案

问题只是出于安全原因,Chrome阻止了本地文件的.load().如果您在服务器上使用它,则可以正常运行,因为所有文件都来自同一位置.

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.





要在本地启用工作版本,请尝试以下操作以启用命令行标记来启动Chrome:

To enable a working version locally, start Chrome with a command line flag enabled by trying:

在Mac OS X中,退出Chrome,在Terminal中输入:

In Mac OS X, quit Chrome, enter in Terminal:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files

在Windows中,退出Chrome,在命令提示符下输入:

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.)

在Linux中,退出Chrome,在终端中输入以下内容:

In Linux, quit Chrome, enter something like this into the terminal:

/usr/bin/google-chrome --allow-file-access-from-files

这篇关于jQuery load()代码在Google Chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆