1

I am using Adminlte theme. Here i have J query libraries that are used for the theme. I have added it at the footer. If i add it in header it is causing issues in UI. My problem is I have ajax loaded pages where I need some libraries(which is also in footer) to be included there. If not, it wont work.

Now if I come back after loading that ajax pages without page refresh THE ISSUES ARE THERE. The problem is due to loading the library twice in a page. what shall i do?

athira
  • 233
  • 1
  • 4
  • 12

2 Answers2

1

Change the way that you load jQuery so it loads only if it's not loaded in the dom yet:

<script type="text/javascript">
if(!window.jQuery){
   var script = document.createElement('script');
   script.type = "text/javascript";
   script.src = "jquery.js";
   document.getElementsByTagName('footer')[0].appendChild(script);
}
</script>

I'm assuming that you have a footer html tag in your document, otherwise use document.getElementById("footer")[0].appendChild(script); to append the script to your #footer tag.

Ethan Kawkji
  • 217
  • 2
  • 9
0

For this kind of problem, I use a POST or GET variable to be passed by ajax function for footer.php so it want load any of the library I dont want to

check my Footer.php

<?php
if(empty($_GET['load_lib']){
?>
<script src=" path to the js file"></script>
<? }else{
//no files to be loaded
} ?>

in Ajax Function I pass load_lib as a parameter with some value 'yes' or 'true' etc... Best luck...

Marmik Bhatt
  • 607
  • 4
  • 16