views:

72

answers:

2

Okay, have a bit of a tricky one (for me anyway, i'm pretty rubbish at jQuery/JavaScript).

I'm pulling in data using standard AJAX (ie, NOT using a framework like jQuery or whatnot... there is a reason for it)

However, I then need to load up a jQuery script as soon as the page has been loaded in. So, here is the question, how do I bind the script once the DOM has been updated? I have been using Ariel Fleser's listen plugin (http://flesler.blogspot.com/2007/10/jquerylisten.html) for picking up on events such as clicks which works a treat, but I can't see how this can be used to listen for a load event.

Any ideas? I'm pretty stumped on this one!!

+2  A: 

What's wrong with:

yourXMLHTTPRequest.onreadystatechange = function () {
  if (this.readyState == 4) {
      doJQueryStuff();
  }
}

Also, what's the reason for not using the AJAX functionality provided in jQuery?

As an aside, it looks like that plugin you mention just replicates the functionality given by the live() and delegate() methods brought into jQuery in 1.4

Matt
Duh, I completely didn't actually think of that! Probably because I am feeling mega ill! Worked a treat though cheers for the quick response!Reason for not using the jQuery AJAX bits is just out of preference and that it is for a large system. I did look into it but found it not quite suitable for what was required.
rich
A: 

In order to parse javascript loaded via ajax, you'll need to use eval(). Although, as far as these things go, a lot of coders consider eval() to be, um, evil... (a link, another link).

Regardless of the right and wrong of eval, this thread on webdeveloper should get you a lot of the way towards a solution.

MatW
That's pretty interesting stuff, can't say i'm particulary good at javascript to be honest!. I have managed to get it doing what I need for now though
rich