1

I try to include Html file into Html But doesn't work. anyone can help me

<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

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

<div id="DivContent"></div>
  • 2
    Have you checked developer tools for any errors in network/console tab ? – darklightcode Sep 02 '21 at 07:20
  • Are the two files in the same folder? – showdev Sep 02 '21 at 07:23
  • heres the error Access to XMLHttpRequest at 'file:///C:/Users/troilus/Downloads/test.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, brave, chrome-untrusted, https. jquery.min.js:2 GET file:///C:/Users/troilus/Downloads/test.html net::ERR_FAILED – KA trending Sep 02 '21 at 07:43
  • Are you running it locally? Is it `second.html` or `test.html`? – showdev Sep 02 '21 at 07:58
  • Does either of these answer your question? [Local xml blocked by cors policy](https://stackoverflow.com/questions/55281250/local-xml-blocked-by-cors-policy) or [Cross origin issue for jQuery .load() for a locally placed file](https://stackoverflow.com/questions/37985922/cross-origin-issue-for-jquery-load-for-a-locally-placed-file) – showdev Sep 02 '21 at 08:19

1 Answers1

0

It seems like you need a local server in order to make it work. Nowadays browsers are strongly restricting file reading through XHR from origin null (aka no web server). Try to use any servers, such as express.js, Node's http, or any php server. Your error will vanish, if the file exists.

BaseScript
  • 381
  • 2
  • 7