1

I know this question has been asked many times , I have gone through all solutions but could not solve the issue.

I am new to programming and want to make a page that load some content in a div with id "content" through java script.

This is my index page

<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="jquery-3.1.1.js"></script> </head> <body> <a href="#">home</a> <a href="#">about</a> <div id="content"> <script src="loader.js"></script> </div> </body> </html> 

and this is my loader.js

$(document).ready(function() { $('#content').load('home.html'); }); 

when I run index.html i get

jquery-3.1.1.js:9536 XMLHttpRequest cannot load file:///C:/Users/Desktop/my_folder/home.html.

all the files are in same folder named my_folder.

6
  • In Jquery latest version .load() method has been deprecated. api.jquery.com/category/deprecated Commented Nov 7, 2016 at 6:18
  • @Samir: Wrong method. The .load to load something into a tag is not deprecated. It is the api.jquery.com/load-event that is deprecated, not api.jquery.com/load Commented Nov 7, 2016 at 6:21
  • @mplungjan, in the reference which i mention, there it is mention .load() method has been deprecated right? .on("load"), is the replacement of that. Please tell me if i am wrong. Commented Nov 7, 2016 at 6:25
  • @Samir yes it is the on("load") shortcut .load - the "load-event" that has be deprecated - the OP is looking at .load("file") not .load("function") Commented Nov 7, 2016 at 6:42
  • @mplungjan the link you gave me is not related to my issue, actually the scenerio of my website is that i have another page home.html which i want to load in content div. Commented Nov 7, 2016 at 8:56

2 Answers 2

2

Unfortunately XMLHttpRequest can not be called to local resources, EVEN IF the HTML ist stored locally.

Its because you can programatically read the contents of local files and send them into the web, what is not allowed.

Sign up to request clarification or add additional context in comments.

Comments

0

i have found the answer of my question

i have changed my script to

 function load_home(){ document.getElementById("content").innerHTML='<object type="text/html" data="home.html" ></object>'; return false; } 

and call this function in content div

thanks for the help :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.