Saturday 15 May 2010

Jquery Multiple independent Ajax calls -



Jquery Multiple independent Ajax calls -

i have table on website multiple rows of data. each row of info can edited on row itself, , @ end of each row save button.

hence if have 10 rows, have 10 save buttons.

i want each save button save respective rows info database via ajax call, , after ajax phone call complete, button text changes "saved". thing is, user may click on multiple save buttons in sequence without waiting previous save complete.

hence need ajax phone call unique each button, i'm having problem finding easy way this. can help out ajax skeleton code? submit ajax phone call including button id , in ajax finish function, button id in homecoming ajax message?

cheers kevin

imagine have variable knows identity of button clicked. lets phone call button.

var button = // button;

when invoke ajax phone call logic such next ...

$.ajax({ // other parameters success: function(data) { $(button).text("saved"); } });

the instance of button variable still in scope when success callback occurs through javascript closure. context of callback still known instance of specific callback.

here specific jsfiddle illustrates solution using table , buttons. instead of calling ajax service, used settimeout() function delay few seconds principle same.

jquery ajax

No comments:

Post a Comment