javascript - Javascript loaded & executed, but not working
问题描述
Totally stumped here. I have a div
that gets its content loaded via jQuery's load()
function:
$("#contentDiv").load("venue-kpis/index.php");
The content is a bootstrap HTML form, nothing fancy, with this javascript embedded at the end:
<script>
$.() => {
if(typeof state == 'undefined') {
$.getScript("/venue-kpis/charts.js");
$.getScript("/venue-kpis/venue-kpi.js", () => { initState($initialJsState) });
}
});
</script>
FYI, state
and initState
is defined in venue-kpis.js
and that's where all the javascript that controls the aforementioned form resides. Anyways, everything works great. At first. The page is accessed via an option in a bootstrap dropdown menu in my department's webpage's header:
<li><a href="#venue" onclick="loadContent('venue')">Venue KPIs</a></li>
Here's my problem: If you're on the page everything is fine, but if you click the link in the header to reload it, the none of the above javascript works; its like those 2 files were never loaded. However, they are loaded, because if I try to explicitly load them (e.g., by removing if(typeof state == 'undefined')
from the above code), I get errors about variable and function re-declarations. Also, I can check the value of state
in the console and its as it should be.
I've tried some different things here. I've tried replacing the calls to getScript
with explicit script
elements appended to head
or body
, but the behavior is the same.
I'm at a loss to explain what's going on; help!
解决方案
推荐阅读
- python - Django App TypeError django.views.i18n.javascript_catalog
- node.js - Docker 构建不会在 `node_modules` 卷中安装软件包
- laravel - events.js:183 抛出未处理的“错误”事件
- react-native - 在本机反应中制作登录表单
- javascript - 如何在我正在创建的网站上添加离线谷歌地图
- python - 当我用 pandas 读取 7GB sqlite3 文件时出现 Pycharm 内存错误
- bash - 通过按升序读取文件,将大量文件合并为一个文件
- c# - 将数组作为参数发送到组件内联
- amazon-web-services - AWS WAF 上的 GEO 块,但有时缺少 Country 标头
- javascript - 我可以在我的 expo 项目中运行 react-native 链接吗?