通过jQuery加载本地文件 [英] Loading local files via jQuery

查看:218
本文介绍了通过jQuery加载本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

花了3个小时阅读参考书,但仍然没有效果,因此请在这里询问.

Spent 3 hours reading reference, but still no effect, so asking here.

操作系统:Windows 7(与之相关吗?)
浏览器:Opera 11.51
的jQuery的:1.6.2

OS: Windows 7 (is it relevant?)
Browser: Opera 11.51
jQuery: 1.6.2

本地计算机上的两个文件,分别位于同一文件夹中的 main.html menu.html .

Two files on a local machine, main.html and menu.html in the same folder.

main.html:

main.html:

<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
    <script type="text/javascript">
      $(document).ready(function(){
        // append contents
        $('#menu').load('menu.html');
      });
    </script>
  </head>
  <body>
    <table>
      <tr>
        <td id="menu"></td>
      </tr>
    </table>
  </body>
</html>

menu.html:

menu.html:

<html>
  <head></head>
  <body>
  menu tree
  </body>
</html>

我猜想,当我打开main.html时,应该有一张表,其中一个单元格包含菜单树"字符串.例如,它在IE中有效.但是Opera没有显示任何结果.

As I guess, when I open main.html, there should be one table with one cell containing "menu tree" string. And it works, for example, in IE. But Opera doesn't show any result.

我使用load()的可选回调调试了东西,它显示load()的结果状态为错误".

I debugged the stuff with optional callback for load(), it shows that result status for load() is "error".

我在做什么错了?

推荐答案

在Opera中,您必须设置标志Allow File XMLHttpRequest(opera:cofig-User Prefs).

In Opera you must set the flag Allow File XMLHttpRequest (opera:cofig - User Prefs).

在Google Chrome浏览器中,您必须使用选项参数--allow-file-access-from-files来运行浏览器,例如:"C:\ Documents and Settings \ User \ Local Settings \ Application Data \ Google \ Chrome \ Application \ chrome.exe-允许从文件访问文件

In Google Chrome you must use option parameter --allow-file-access-from-files for run browser, for example: "C:\Documents and Settings\User\Local Settings\Application Data\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files

这篇关于通过jQuery加载本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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