简体   繁体   English

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

[英]Reloading of the js scripts via jquery load /ajax

Hi I Am working on a project.The design of the project is like this 嗨,我在一个项目上。项目的设计是这样的

<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>

The problem ,that i am facing is , suppose i designed a page that need a bootstrap and jquery 我面临的问题是,假设我设计了一个需要引导程序和jquery的页面

So i placed the file in the page but these files are also present in the homepage where i am going to load the contents using the ajax.So we end-up having two times jquery and bootstrap on the page , this causes few problems like my menu stop working 所以我将文件放在页面中,但这些文件也存在于我要使用ajax加载内容的主页中,因此我们最终在页面上有两次jquery和bootstrap,这会引起一些问题,例如菜单停止工作

and if i remove the bootstrap from the page that i am going to load few functionality of the page stop working like bootstrap modals doesn't show up and say undefined functions but bootstrap is present in the main page where i am loading this page html using ajax. 如果我从要加载的页面上删除引导程序,则该页面的一些功能会停止工作,如引导程序模态不会显示并说未定义函数,但是引导程序存在于我要加载此页面的html主页中阿贾克斯。

one thing i am sure it a project design flaw but this project is on a level where we cant change the structure . 我确信这是项目设计的缺陷,但是这个项目处于我们无法改变结构的水平。

So i need help that how should i stop reloading of the scripts and maintain every thing working. 因此,我需要帮助,该如何停止重新加载脚本并保持所有工作正常进行。

One more thing the main page is index.html and back-end is in spring framework 主页的另一件事是index.html,后端在spring框架中

I can see two posible solutions: 我可以看到两个可能的解决方案:

  1. If you are putting full HTML pages into <div id=container> , put them into an iframe . 如果要将完整的HTML页面放入<div id=container> ,请将它们放入iframe
  2. Stript the HTML header from you imported pages and create an appropratie backbone view to show this contents. 从导入的页面上剥离HTML标头,然后创建一个适当的主干视图以显示此内容。

Are you sure that using simple JQuery $load() over that div is not getting the includes of the main page? 您确定在该div上使用简单的JQuery $ load()不会获得主页的包含吗?

I always add HTML code to my DOM using load and I dont need to include the js or css for every injected page. 我总是使用负载将HTML代码添加到DOM中,并且不需要为每个插入的页面都包含js或CSS。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Ajax用来自servlet的数据加载JQuery Datatables - Load the JQuery Datatables with the data from the servlet via Ajax Ajax成功时不会重新加载jsp - Ajax not reloading the jsp on success Spring / Thymeleaf 使用 select 重新加载 div 后模板问题通过 ZA34A6659BCEAE779F28proble18 () - Spring / Thymeleaf template problem after reloading div with select via AJAX (problem with *localidad) 不通过jQuery中的Ajax调用Java Action - Not Calling java Action via Ajax in jQuery 在脚本中包含Rhino shell方法或加载其他js脚本的简单方法? - Easy way to include Rhino shell methods in scripts or to load other js scripts? 调用servlet使用jquery ajax加载数据? - Calling servlet to load the data using jquery ajax? 如何在不重新加载页面的情况下使用jquery中的ajax使用参数调用playframework api? - How to call playframework api with parameters using ajax from jquery without reloading the page? 如何在不重新加载整个页面的情况下使用AJAX和JQuery刷新我的JSP? - How can I refresh with AJAX and JQuery my JSP without reloading the whole page? 如何通过ajax将变量发送到服务器(Java),然后使用响应加载数据表 - How to send a variable to the server (Java) via ajax, then load a DataTable with the response 使用JS / jQuery / AJAX和控制器在Java中进行分页 - Pagination in Java using JS/jQuery/AJAX and controllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM