0

So I have a menu:

<nav id="side-nav">
<ul>
<li><a href="consulting">Consulting</a></li>
etc..

jQuery reads

$(document).ready(function() {
  $( "#side-nav ul li a" ).on( "click",function() {
   $('#services-content').load('side-menu.html #' + $(this).attr('href'));
    return false;
  });
});

and have an html file with corresponding id's to the href. It does not load. Thought i followed exactly as per jquery website. Whats wrong ?

Even if I have it hard coded, nothing is loaded :

<div id="services-content">

</div><!--load services content in here-->

<script type="text/javascript">
   $(document).ready(function() {
     $('#services-content').load('side-menu.html #consulting');
   });
</script>
chucky
  • 153
  • 3
  • 13

2 Answers2

0

Read Local files doesn't load with Ajax in Chrome but Work on Firefox

Are you working locally on your machine, without any webserver? Chrome does not allow loading files via AJAX from your file system (see bugreport).

You may use XAMPP or something similar to serve your files via a local webserver.

If you are on Windows, XAMPP is probably the easiest way to get your local webserver up and running: http://www.apachefriends.org/en/xampp.html

On Mac, you may also use MAMP http://www.mamp.info/en/index.html

You may also force Chrome to allow local file access on Windows if you are starting it with --allow-file-access-from-files, more information in this stackoverflow question

Community
  • 1
  • 1
Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
0

Looks like a scope problem. I didn't test this, so don't shoot me.

$(document).ready(function() {
  $( "#side-nav ul li a" ).on( "click",function(e) {
    e.preventDefault();

    var $this = $(this);
    $('#services-content').load('side-menu.html#' + $this.attr('href'));
  });
});
keyboardSmasher
  • 2,661
  • 18
  • 20