jQuery .load()在Chrome中不起作用 [英] jQuery .load() not working in Chrome

查看:123
本文介绍了jQuery .load()在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



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.

编辑:我应该补充说我在本地运行,它永远不会被部署到Web服务器上。

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中使用,但不能用于Chrome。

I've tried .load('file:///C:/path/to/test.htm') which works in FF but not Chrome.

推荐答案

这是Chrome所解释的相同来源策略(或具有相同效果的错误)。尝试使用 - 允许从文件访问文件运行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屋!

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