0

So, I have this code in index.html:

<td><a id="link" href="">Vídeos</a></td>

and then

<div name="content" id="content"></div>

I want to load a page named vid_content.html

I tried a lot of code I found everywhere but nothing went right..

PS: all the pages are local in the same folder!

The last thing I tried was:

$(document).ready(function(){ 
    $("#link").click(function(){ 
        $("#content").load("vid_content.html");
    });
}
Jason P
  • 26,984
  • 3
  • 31
  • 45
jbarradas
  • 2,031
  • 3
  • 17
  • 22

5 Answers5

1

use this

 $('#content').load('/path/to/vid_content.html');
Rohit Agrawal
  • 5,372
  • 5
  • 19
  • 30
0

You should be able to make use of .html() within jQuery to define what the html contained within the div is.

    $(document).ready(function(){ 
      $("#link").click(function(){ 
        $("#content").html("vid_content.html");
      });
    }
droessmj
  • 1
  • 1
0

There's a few problems with the code. Firstly, the Ajax request won't work unless you're running this on a local server. Simply opening the HTML file in Chrome won't work. Secondly, you need to pass in the event object to the click handler so that you can stop the page reloading when you click on the link, like so:

$(document).ready(function(){ 
    $("#link").click(function(e){ 
        $("#content").load("vid_content.html");
        e.preventDefault();
    });
});

Lastly, you were missing the final closing bracket from the jQuery ready function.

scf1001
  • 251
  • 1
  • 5
  • what should I put in href of the #link ? I will put it online on a free domain to test it. – jbarradas Jan 16 '14 at 21:53
  • Just put a # for the href. It's not being used because the javascript is working instead. Alternatively you could make the href point to the `vid_content.html` file, and then the javascript can use the href for the Ajax request. – scf1001 Jan 16 '14 at 21:56
0

Already got a solution!

Done it this way:

function load_vids(){ document.getElementById("content").innerHTML='<object type="text/html" data="vid_content.html #content" style="width:811px; height:570px"></object>'; }

And this:

<td><a id="link" href="#" onclick="load_vids()">Videos</a></td>

Thank you all for help!

jbarradas
  • 2,031
  • 3
  • 17
  • 22
0

Save this into "firstpage.php". with -> jQuery v2.2.3

$(document).ready(function() {

    $('#content').load("secondPage.php", function() {
        //do something
    });

    $(document).on('click','#third',function(){
        $('#content').load("thirdPage.php", function() {
            //do something
        });
    });

});

Into secondPage.php

page 2<br>
----------------------<br>
<a href="#" id="third">load third</a>

Into thirdPage.php

hello world
flexicon
  • 102
  • 1
  • 11