Question

I can see that the $.getScript bit of jquery would be handy once it's working, but it's the last little bit I'm having problems with. I'm suspecting the problem is caused by the way I'm loading JS files. How do I get this to work? My index.html is actually index.php and has very little between the body tags. I'm using jquery 1.7.1

<body id="btLive">
     <script>
          buildInterfaces();
     </script>
</body>

buildInterfaces() resides inside a document named layoutLoader.js. In that file, I have the following:

$(document).ready(function() {
     $('#hToggle').click(function() {
          aaa = "Not working.";
          $.getScript('test.js', function() {
               alert(aaa);
          });
          toggleHoverPanel();
     });
});

As my test, test.js is in the same folder as layoutLoader.js and contains only the following:

aaa = "Successful Load."

When I click on the button hToggle, toggleHoverPanel takes place and I get no alert. If I place an alert after aaa="Not working."; I get the alert I expect, telling me it's not working. I have a number of items that I need to use this for, but for the life of me, I cannot get it to work. Help?

Was it helpful?

Solution

With high probability test.js file could not by found. Add this piece to your code and try again:

$(document).ajaxError(function(event, request, settings){
  alert('error loading: ' + request.status);
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top