2

I am using jQuery in a page. I am calling the script from the head section through GoogleApis CDN. At the end of my page i use

$(document).ready(function () {

   // code
   //
   // do something
   // 


   //
   setInterval(function() { location.reload(true); }, 40000);

 });

The problem is that many times after the page refreshes I am getting the error:

$ is not defined 

on document.ready line

and the script stops.

For some reason the jquery in the head is not loaded and throws the error. This happens only when the page loads through javascript location.reload(true) method.

Why?

The page is placed in an iframe. But the error is also happening if it is called directly.

sski
  • 830
  • 1
  • 8
  • 15

1 Answers1

0

When you write location.reload(true); with true means browser will bring the current page from the server each time page makes a reload. that's also means not cache handle here.

In this case, i would recommended to verify all page been loaded:

var allLoaded = setInterval(function() {
  if (/loaded|complete/.test(document.readyState)) {
    clearInterval(allLoaded);  // stop the interval
    callYourInitFuction();   // the story start here
  }
}, 10);

with this senario when all your scripts take in place, you can go on the way.

Tal
  • 205
  • 1
  • 8