View Full Version : Simple js won't load in ajax generated code

10-09-2010, 02:47 AM
Greetings everyone,

I'm learning javascript as I go and have decimated a client's site to incorporate ajax loads etc.

The problem I've run into, however, is that a javascript won't load... here is the index code in question:

<div id="bodycontent">
<script type="text/javascript">

This code is working great however on "home.html" this code is not working at all.

<div id="flashPic">
<script type="text/javascript" src="scripts/images.js"></script>

So, I guess the question is, how do you load a javascript... script, inside of ajax generated content?

Thanks for helping a beginner,


10-12-2010, 08:52 PM
When a page loads, it first loads the HTML, then makes more requests to load other resources if they're present in the HTML probably while loading it.

On the first block of code, I'd think that it executes the Javascript as soon as it sees it, so HTML that hasn't been loaded won't exist yet. While the second block of code, it sees a resource and makes a request to download it. There would be a delay for the resource to be downloaded, so the HTML may have been completely loaded given the delay.

If you want the first block of code to work, you can try something like this...

window.load = function () {