jQuery: The Write Less, Do More JavaScript Library

Need a little assistance mapping event source to AJAX callbacks

View: New views
3 Messages — Rating Filter:   Alert me  

Need a little assistance mapping event source to AJAX callbacks

by mmiller-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have a decent amount of JQuery success under my belt at this point
but I am in need of some page / request architecture help.

I have a table of user data, one row per user. Each row has a 'change
role' button wired up with a click handler that makes an ajax ($.ajax)
post to a webservice. Response times are 3-5 seconds, but the general
goal is to let the user move onto other rows in the table and trigger
the same event for a different record. Assume that the responses from
the webservice are generic and do not identify the record affected by
the request.

My problem is figuring out how I correlate the success or error
callbacks with the table row from which the event originated (to
remove the activity indicator or report an error). I'm blind to
finding a way to pass additional data such a row DOM reference (not
request related data) through to the success or error callbacks.

Could one of you talented folks illuminate the path for me or
otherwise correct my thinking / approach?

With great appreciation for your time,

Mark

Re: Need a little assistance mapping event source to AJAX callbacks

by dave.methvin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> My problem is figuring out how I correlate the success or error
> callbacks with the table row from which the event originated

The click handler gets an event object with an event.target that
should tell you what element was clicked. Inside the click handler
you'll do the ajax call which will have the success function nested
inside it. You can just use event.target inside the success function
to get to the element that was originally clicked to fire the ajax
that just successfully finished. At least I think that should work...
You should could even use event delegation and set a single click
handler for the whole table and just do a little data gathering to
figure out what action to take.


Re: Need a little assistance mapping event source to AJAX callbacks

by mmiller-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thank-you Dave. The fog is lifting now...


On Jul 23, 7:11 pm, Dave Methvin <dave.meth...@...> wrote:

> > My problem is figuring out how I correlate the success or error
> > callbacks with the table row from which the event originated
>
> The click handler gets an event object with an event.target that
> should tell you what element was clicked. Inside the click handler
> you'll do the ajax call which will have the success function nested
> inside it. You can just use event.target inside the success function
> to get to the element that was originally clicked to fire the ajax
> that just successfully finished. At least I think that should work...
> You should could even use event delegation and set a single click
> handler for the whole table and just do a little data gathering to
> figure out what action to take.