简体   繁体   English

如何使用 JQuery 加载 HTML 页面?

[英]How to Load HTML Page Using JQuery?

I am trying to load an external html file using JQuery.我正在尝试使用 JQuery 加载外部 html 文件。 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 );
  }
});

});
     

  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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