-1

I am using this code, When I run this code in browser I am getting a blank page, Help me out please, Thanks in advance.

<html> 
  <head> 
    <script src="js/jquery-3.3.1.js"></script>
    <script> 
    $(function(){
      jQuery.noConflict();
      $("#includedContent").load("a.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="includedContent"></div>
  </body> 
</html>

my a.html is following

<html>
    <p>this is included file</p>
</html>
Jamie Southwell
  • 93
  • 1
  • 2
  • 8

4 Answers4

2

you can not nest html tags inside each other. Best solution is to use a iframe instead.

$("#includedContent").html("<iframe src='a.html'></iframe>"); 
Josh Stevens
  • 3,943
  • 1
  • 15
  • 22
  • your file path is incorrect then.. open that html file in a web page, paste the entire URL into the src then it should work. – Josh Stevens Jul 08 '18 at 11:08
0

enter image description here

For security reasons browsers don't allow to load files using such methods which involves XHR/AJAX.

$("#includedContent").load("a.html");

You need to host/deploy files on server, try using XAMPP/WAMPP or equivalent.

enter image description here

0

You should use load() if you are trying to load a specific selector but if you are trying to load the entire page use get(), please see in this SO the differences between jQuery.get() and jQuery.load();

$.get('a.html', appndHtml);
function appndHtml(data){
   $("#includedContent").prepend(data);
}
Ram Segev
  • 2,563
  • 2
  • 12
  • 24
0
 $(document).ready(function() { 
   $('#some-container').load('path-name.html'); 
 });

The document should be ready, or fully loaded.

Dan K
  • 38
  • 4