1

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

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


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

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:

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

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.

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

What am I doing wrong?

2
  • Are you running under a web server (http://) or a folder (file://)? Commented Oct 5, 2011 at 20:02
  • I'm running within local folder.
    – iehrlich
    Commented Oct 5, 2011 at 20:33

2 Answers 2

4

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

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

2
  • Yes, this helped, but one more question. This structure (meaning interface HTML file and many other cross-referenced files which are uploaded to the interface) is intended to be deployed on CD-disk and delivered to end-users. Of course, it is not an option to ask every end-user to turn browser flags on and off. Is there a general solution for the problem?
    – iehrlich
    Commented Oct 5, 2011 at 20:27
  • If it's on cd, then it's static - why are you dynamically loading the menu? Just add the html without using js. Commented Oct 6, 2011 at 8:00
0

You probably want to get rid of the <body>, <head> and <html> tags in the Menu.html.

The way you're doing it now is invalid HTML because there is only one <body>, <head>, and <html> tag allowed in a document.

Change Menu.Html to

<p>
    Menu
</p>

Try that!

2
  • Did this, but still no effect.
    – iehrlich
    Commented Oct 5, 2011 at 19:57
  • Make sure you are on a server too. Like not on localhost, that could be your problem.
    – Eganr
    Commented Oct 5, 2011 at 20:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.