du8794 2012-01-26 23:01
浏览 79
已采纳

如何让$ .getScript正常工作?

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?

  • 写回答

1条回答 默认 最新

  • douganmo1121 2012-01-27 02:57
    关注

    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);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办