-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>
5
  • Is there any error log on the console or network logs Commented Jul 8, 2018 at 10:53
  • try replacing <div id="includedContent"></div> with <iframe src="a.html"></iframe>, if still there is blank page, then you have issues with url Commented Jul 8, 2018 at 10:58
  • yes It works, @Arvind Commented Jul 8, 2018 at 11:01
  • @JamieSouthwell, are you browsing file with file:/// protocol? Commented Jul 8, 2018 at 11:03
  • Yes I am @Arvind Commented Jul 8, 2018 at 11:06

4 Answers 4

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>"); 
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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);
}

Comments

0
 $(document).ready(function() { 
   $('#some-container').load('path-name.html'); 
 });

The document should be ready, or fully loaded.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.