Ajax and JS libraries

  • Posted by a hidden member.
    Log in to view his profile

    Jul 15, 2011 1:52 AM GMT
    Im hoping someone here has a clue about this but anyway. The deal is I created this fully ajax site in which I have an image gallery under the gallery page. All my pages are loaded through ajax and as a result the gallery simply cant access any of the already loaded js files on the index page. Basically any code that depends on preloaded JS libraries wont work if its inside the content that is being loaded dynamically. Is there a way to load the libraries dynamically as well?
  • Posted by a hidden member.
    Log in to view his profile

    Jul 15, 2011 3:10 AM GMT
    well what javascript libraries do you want to load. a lot of people use jquery and dojo to help build sites.
  • inmidair

    Posts: 70

    Jul 15, 2011 3:22 AM GMT
    I don't completely understand what you're getting at, but I can try to help...

    1.) If you're switching to an entirely new page, for example index.html to gallery.html, then you've lost your javascript files and need to load them again.

    2.) If you're not switching to a new page, but changing views within a single page (it looks like the index, AJAX magic, now it looks like the gallery!) then you should still have your javascript files loaded and ready for use.

    If you are in situation #2 and it's not working, and you're using frames or iframes, that may be the cause of your problem.

    If none of the above is causing your problem, you might use object oriented programming to create a specific namespace for your functions. Then the object gets instantiated when you first load the page in "index" mode, and that object should immediately be available as the gallery bits load asynchronously.

    Also, if you use object notation to put your functions in a specific namespace, that might help overcome any issues you might be having around variable scope.

    Does that help at all? If not, can you be more specific about what you're trying to do and how it's not working? icon_biggrin.gif
  • Posted by a hidden member.
    Log in to view his profile

    Jul 15, 2011 3:25 AM GMT
    jquery should be able to do this. Though an example of what you're trying to do would be helpful?
  • Posted by a hidden member.
    Log in to view his profile

    Jul 15, 2011 4:29 AM GMT
    isaidwhat saidjquery should be able to do this. Though an example of what you're trying to do would be helpful?


    JQuery is where it's at! You can do event binding after the page has been loaded by ajax.

    http://api.jquery.com/live/

    .live(); will allow you to "Attach a handler to the event for all elements which match the current selector, now and in the future."

    I too have encountered this problem. Nothing you load in via AJAX when you first load the javascript libraries are present in the DOM and therefore misses the binding of events. If you ARE using JQuery, the live() function can be used to get around this.
  • Posted by a hidden member.
    Log in to view his profile

    Jul 15, 2011 7:30 AM GMT
    Thanks a lot guys, I finally figured how to get it working and yes it's a fully Ajax site so only index.php is loaded everything else loads within the same page. At first I was loading all my libraries on index but that wouldn't work. I had to dynamically load the libraries by using DOM to force the head to trigger a request for the js file I needed. It's working fine on chrome, safari, ie8 and firefox icon_biggrin.gif
  • Posted by a hidden member.
    Log in to view his profile

    Jul 15, 2011 3:11 PM GMT
    that wont work in ie shitty 6..

    but more importantly jQuery is more suited to this kind of stuff now t's good, fast, got shit built in...

    it's pretty

    I like pretty
  • Posted by a hidden member.
    Log in to view his profile

    Jul 15, 2011 5:26 PM GMT
    lilTanker saidthat wont work in ie shitty 6..

    but more importantly jQuery is more suited to this kind of stuff now t's good, fast, got shit built in...

    it's pretty

    I like pretty


    A lot of things on this website don't work on iE6 because I'm not supporting IE6 at all. Its 2011 time to move on.

    And ya the site is jquery powered I just used plain DOM js for this specific task cause I had no other clue what to do.
  • Posted by a hidden member.
    Log in to view his profile

    Jul 18, 2011 2:04 AM GMT
    charlitos saidA lot of things on this website don't work on iE6 because I'm not supporting IE6 at all. Its 2011 time to move on.

    And ya the site is jquery powered I just used plain DOM js for this specific task cause I had no other clue what to do.

    OOH then jude answered your question.

    If you can keep to just one way of doing things, ie, either your own way, jquery or what ever it'll help reduce overhead, produce easier to read code and will let you update things much more easily in the future