Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple js won't load in ajax generated code

    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:
    Code:
    <div id="bodycontent">
    <script type="text/javascript">
     ajaxpage('home.html','bodycontent')
    </script>
    </div>
    This code is working great however on "home.html" this code is not working at all.

    Code:
    <div id="flashPic">
    <script type="text/javascript" src="scripts/images.js"></script>
    </div>
    So, I guess the question is, how do you load a javascript... script, inside of ajax generated content?


    Thanks for helping a beginner,

    theaer

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    52
    Thanks
    0
    Thanked 4 Times in 4 Posts
    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...
    Code:
    window.load = function () {
      ajaxpage('home.html','bodycontent')
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •