jQuery code in ajax loaded content only runs once

Posted by Michael Howland on Stack Overflow See other posts from Stack Overflow or by Michael Howland
Published on 2010-05-13T13:27:13Z Indexed on 2010/05/13 13:44 UTC
Read the original article Hit count: 285

Filed under:
|
|

I have been looking around SO for a while and haven't been able to find anything that matches my issue, which I'm not even sure I can explain that well, so take that for what it's worth.

I have a page that loads content into a div via AJAX (using the .load() method). There are several links in the navigation, meaning the content will change while navigating the site without refreshing the entire page.

(Actually, to be honest, I just cribbed the DocTemplate layout [http://css-tricks.com/examples/DocTemplate/] from css-tricks.com. Apparently while I'm not a re-invent the wheel type programmer, I am a bash my head against the wheel incessantly to get it to work programmer.)

So, index.php loads up some DB content in a div. There is also a jQuery UI modal input form on index.php. Essentially, the only HTML on the page is an empty div and a form. This all works fine, until I call up another page, then go back to index.php. The DB content is not loaded, and my form is shown there in all its naked glory. I know why this is happening. The page was not refreshed, nothing kicked off the code to load the content and hide the form.

My question is, how can I ensure that the AJAX .load() and the .dialog() will run when loading index.php again? Is it even possible?

Thanks, and my apologies for the length. I get verbose when I'm confused.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ui