jQuery not working on ajax pages

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

jQuery not working on ajax pages

Post by GeXus »

I've had this problem before but never found a solution, so here's goes..

I have some pages that are loaded via ajax... basically, a page is being loaded into a div. I want the content within that div (or the remote page) to use jQuery. the document.ready does not work, neither do any other functions.

Any idea how to do this?

Also to note, I have jQuery being included in both the remote page and the parent.

Thanks!
User avatar
lukewilkins
Forum Commoner
Posts: 55
Joined: Tue Aug 12, 2008 2:42 pm

Re: jQuery not working on ajax pages

Post by lukewilkins »

I personally prefer Prototype: http://www.prototypejs.org/ :wink:

BUT, jQuery will work the same way in which once a div is loaded with content (via Ajax) it is "part" of the parent page. Meaning, it can access all of the functions present on that page including those part of jQuery.

If you don't understand what I'm saying, leave your code here and I'll take a look at it for you.

Luke
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: jQuery not working on ajax pages

Post by GeXus »

Ahhh.. I see... However, it still doesn't seem to work.. I must be doing something wrong..


Here's snippets of the code

Main Index (Parent)

Code: Select all

 
$(document).ready(function(){
$('#delete').click(function(){
        alert('test');
    });
});
 
Ajax Page being loaded into <div id="content"></div> from parent.

Code: Select all

 
<a href="#" id="delete">delete</a>
 
I put this in as a test and it didn't work...
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: jQuery not working on ajax pages

Post by GeXus »

I got it.. I was calling it before the ajax was executed... Thanks so much!!! Seems very simple, but literally spent hours trying to figure it out.. thanks!
User avatar
lukewilkins
Forum Commoner
Posts: 55
Joined: Tue Aug 12, 2008 2:42 pm

Re: jQuery not working on ajax pages

Post by lukewilkins »

No problem. Glad it is working for you!

Luke
Post Reply