Jquery ajax load not working

Posted by Slay on Stack Overflow See other posts from Stack Overflow or by Slay
Published on 2012-10-13T03:27:07Z Indexed on 2012/10/13 3:37 UTC
Read the original article Hit count: 124

Filed under:
|
|

This is my code:

test.html

<html>
  <head>
    <title>test</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script>
      $(document).ready(function(){
        $(window).bind('hashchange', function(){
          $('#result').load('test2.html', function(){
            alert('Load was performed.');
          });
        });
      });
    </script>
  </head>
<body>
  <a href="#Test1">Test 1</a>
  <a href="#Test2">Test 2</a>
  <div id="result"></div>
</body>
</html>

test2.html

<h3>This is content from test2.html</h3>

I want to detect the specific page to load using window.hash in change. For instance if user go to

http://localhost/test.html#test2

The main container(result) in the page will do an ajax load call to test2.html to get the content.

I can't manage to get this simple code working. Appreciate if someone can guide me in the right direction. Thanks.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery