0

I was trying to display a changing temperature value, in an html file, using the js. But all I got was a blank page. I included the jQuery library in the same directory, in addition to the txt file I was trying to parse. Also tried changing the txt file to a php file like in the original code I got from here.

Apparently there was nothing wrong with my code. So what could be the matter?

<html>
<head>
<title>Auto-Refresh DIV</title>
</head>
<body>
<div id="auto"></div>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready( function(){
$('#auto').load('load.txt');
refresh();
});
function refresh()
{
    setTimeout( function() {
      $('#auto').load('load.txt');
      refresh();
    }, 2000);
}
</script>
</body>
</html>

After getting this response from my console:

XMLHttpRequest cannot load file:///C:/foo/load.txt. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource.jquery-1.11.1.min.js...

I tried loading the page through localhost, as this post suggested. But the page was still blank...

Community
  • 1
  • 1
  • Are you seeing any errors in the console? Can you provide the contents of the text file? – Michael Hommé Dec 15 '14 at 18:14
  • your code is working fine try to check your file paths. – Suchit kumar Dec 15 '14 at 18:18
  • everything is kept in the same directory in this example – Davíð James Róbertsson Berman Dec 15 '14 at 21:04
  • Look at your browser's developer tools. Look at the JavaScript console. Does it report any errors? Look at the Net tab. Is the request being made? Does it get a response? Do they contain the data you expect? – Quentin Dec 15 '14 at 21:05
  • After localhost load didn't work I noticed that I had accidentally named my text files with double text file extensions in notepad load.txt.txt not seen to me because of the view settings on the windows I'm using. So, no wonder the js couldn't find its target. It works now that I renamed them. Thanks for all the suggestions guys. Especially @suchit – Davíð James Róbertsson Berman Dec 15 '14 at 22:40

0 Answers0