Danny Liu
Danny Liu

Reputation: 519

Cannot load html file to another html file with jQuery

I'm getting a 404 file not found when I try to include an html file into another html using jQuery. Here's my code inside my index.html

<script> 
    $(function(){
      $("#portfolio").load("list.html"); 
    });
</script> 

The way my file directory is setup is that both index.html and list.html are within a views folder and being served via a node.js server.

Upvotes: 1

Views: 732

Answers (1)

caulitomaz
caulitomaz

Reputation: 2331

The docs explains that you may use a callback parameter on the load method, which gives your information about the load request.

$( "#portfolio" ).load( "/list.html", function( response, status, xhr ) {
  if ( status == "error" ) {
    var msg = "Sorry but there was an error: ";
    $( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
  }
});

Also, you may check the Network tab of your browser´s Developer Tools to get more information, including URL that your script tried to reach. Debug from there.

Upvotes: 2

Related Questions