Link to home
Start Free TrialLog in
Avatar of Shaye Larsen
Shaye Larsen

asked on

Loading content into a div via jQuery doesn't include external files?

I am loading content from an external file into a div via jQuery.

For some reason, like the other ajax content loading scripts, it does not pull in the javascripts, css files, etc.  which are referenced in my external file, making the page, once loaded, in look like junk. My external file relies completely on the css file it references and also needs a js file too.

I know this can be done because I have used a jQuery lightbox popup that can load its contents via ajax from an external file and it loads including the necessary css and js files.

Does anyone know how to get this to work or knows of a good plugin that will do this?

The below javascript is what I am currently using:
<script type="text/javascript">
$(document).ready(function() {
$("#loadAjaxSite").load("/sitecreator/site_templates/test-green/index.jsp");
});
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shaye Larsen
Shaye Larsen

ASKER

Thank you.

I tried it but I can't view it on the page... I only get the alert from the callback.

This is what I did with the script at the link you showed me:
<%
String siteTemplate = "test-blue";//or test-green
%>
<!-- dynamic ajax content to load in template -->
<script type="text/javascript" src="../js/sitecreator_load_ext_files.js"></script>
<script type="text/javascript">
var globalCallback= function(){
alert('all files are loaded!!!');
}
$.include( ['/sitecreator/site_templates/<%=siteTemplate%>/main.css',
'/sitecreator/site_templates/<%=siteTemplate%>/index.jsp'] ,globalCallback);
</script>

Open in new window

Right on that was enough to do the trick. Thank you very much!
Thanks