normally async, but with the $.ajax function you can override all sorts of
stuff!

my opinion is that sync is amost never the way to go, With a proper callback
and re-binding to catch the new elements there should be no reason for sync.


On 2/7/07, Paul <[EMAIL PROTECTED]> wrote:

 Gotcha, thanks for clarifying.



Are all the ajax methods asynchronous?  (.get, .post etc)


 ------------------------------

*From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Dan G. Switzer, II
*Sent:* Wednesday, February 07, 2007 3:38 PM
*To:* 'jQuery Discussion.'
*Subject:* Re: [jQuery] jQuery operations on ajax data



Paul,



I was just pointing out that you only really need to reinitialize the
click() handler on images in the #content layer (the one where you're
loading the content.) There's no reason to update the entire DOM again. Just
the segment you loaded into DOM.



-Dan


  ------------------------------

*From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Paul
*Sent:* Wednesday, February 07, 2007 5:14 PM
*To:* 'jQuery Discussion.'
*Subject:* Re: [jQuery] jQuery operations on ajax data



Dan,



Thank you.  Using the callback to reinit did the trick.



Oh and I have no idea what you meant about only triggering off the handler
for the #content layer…  Will you explain?



-Paul


 ------------------------------

*From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Dan G. Switzer, II
*Sent:* Wednesday, February 07, 2007 2:53 PM
*To:* 'jQuery Discussion.'
*Subject:* Re: [jQuery] jQuery operations on ajax data



Paul,



The load() method is asynchronous. You'll need to use the callback to fire
off a trigger to reinitialize your img click handler. Also, I'd only trigger
off the handler for the #content layer.



-Dan


  ------------------------------

*From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Paul
*Sent:* Wednesday, February 07, 2007 4:30 PM
*To:* 'jQuery Discussion.'
*Subject:* Re: [jQuery] jQuery operations on ajax data



I think I already am, Andy.  Here's my first few lines; do I need to do
something more?  (And thanks, btw.)



$(function() {

                 /* Load the initial screen content */

                 $("#content").load("includes/sh4-welcome.cfm?nocache=
<cfoutput>#getTickCount()#</cfoutput>");

                 /*  Assign the onclick event handler to all the images on
the keypad. */

                 $("#keypad img").click(function() {

                          ...


 ------------------------------

*From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Andy Matthews
*Sent:* Wednesday, February 07, 2007 2:12 PM
*To:* 'jQuery Discussion.'
*Subject:* Re: [jQuery] jQuery operations on ajax data



You just have to reassign the function to the images after you load in
content.


 ------------------------------

*From:* [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] *On
Behalf Of *Paul
*Sent:* Wednesday, February 07, 2007 3:14 PM
*To:* 'jQuery Discussion.'
*Subject:* [jQuery] jQuery operations on ajax data

I'm using jQuery to assign a function to every image within a div on my
page:



$("#keypad img").click(function() { ...



It worked great, until I set about organizing the screens in my
single-page application.  I want to load the content dynamically as a user
moves about the application, so I'm trying to initialize the first screen
like so:



$("#content").load("includes/sh4-welcome.cfm");



This renders the html properly, but it breaks the jQuery click function I
was assigning to the images. (The #keypad div is within the file being
loaded at runtime.)  There aren't any JS errors, but nothing happens when I
click.  If I remove the ajax call, and instead put the data back inline the
good old-fashioned way, the click functions work again.



Is there a rule I don't know about using jQuery functions on ajax-loaded
data?



-Paul



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/




--
Ⓙⓐⓚⓔ - יעקב   ʝǡǩȩ   ᎫᎪᏦᎬ
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to