简体   繁体   中英

How to Load HTML Page Using JQuery?

I am trying to load an external html file using JQuery. But, the following code does not work:

<!-- JQuery Code-->
                 <script>
                    $(document).ready(function(){
     
        
        $("#div1").load("header.html");
      
    });
                  </script>
            </head>
         <body>
          
             <div id="div1"></div>
    
          </body>

the following code with debug !! to see what is your problem

$( document ).ready(function() {
    console.log( "ready!" );
    $("#div1").load( "header.html", function( response, status, xhr ) {
  if ( status == "error" ) {
    var msg = "Sorry but there was an error: ";
    $( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
  }
});

});
     

  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM