通过jquery load / ajax重新加载js脚本

时间:2014-06-11 09:53:58

标签: java javascript jquery html spring

您好我正在开展一个项目。该项目的设计就像这样

<html>
<head>
some intail scripts that are needed like bootstrap and jquery  and page specific scripts goes here that is required for the first launch
</head>
<body>
<div id=menu>
<!--we put bootstrap menu here-->
</div>
<div id=container>
<!--we load different html pages here using ajax call inside the div when user clicks on the menu we call page html using ajax and append  it here -->
</div>
<div id=footer>
<!--Footer contents  come here-->
</div>

</body>

我面临的问题是,假设我设计了一个需要引导程序和jquery的页面

所以我把文件放在页面中,但这些文件也出现在我要使用ajax加载内容的主页中。所以我们最终在页面上有两次jquery和bootstrap,这导致很少问题 就像我的菜单停止工作

如果我从页面中删除引导程序,我将加载页面停止工作的几个功能  bootstrap modals没有显示并说出未定义的函数,但是在我正使用ajax加载此页面html的主页面中存在bootstrap。

有一件事我确信这是一个项目设计缺陷,但这个项目处于我们无法改变结构的水平。

所以我需要帮助,我应该如何停止重新加载脚本并保持所有工作。

主页的另一件事是index.html和后端是在spring框架中

2 个答案:

答案 0 :(得分:0)

我可以看到两个可行的解决方案:

  1. 如果您要将完整的HTML网页放入<div id=container>,请将它们放入iframe
  2. 从导入的页面中删除HTML标题,并创建适当的骨干视图以显示此内容。

答案 1 :(得分:0)

你确定在该div上使用简单的JQuery $ load()是不是得到了主页的包含?

我总是使用加载将HTML代码添加到我的DOM中,我不需要为每个注入的页面包含js或css。

    $('#container').load("url_controller_where_you_will_render_the_html_to_inject");