Suppose there is such a code. When clicking on a link, an ajax request should be sent. Data acquisition can take a lot of time, during which it is very easy to have time to click another 1-2 links. Given that $ .ajax works asynchronously, the question arises. And how to transfer to error and success callbacks the link to the element on the click on which the data loading was started?

$(function(){ $('table tr').on('click', 'td>a', function(){ $(this).parent().parent().after('<tr>' +'<td>Additional row</td>' +'<td>Some data...</td>' +'<td>Some data...</td>' +'</tr>'); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tbody> <tr> <td><a href="#">Load additional rows</a></td> <td>Some data...</td> <td>Some data...</td> </tr> <tr> <td><a href="#">Load additional rows</a></td> <td>Some data...</td> <td>Some data...</td> </tr> <tr> <td><a href="#">Load additional rows</a></td> <td>Some data...</td> <td>Some data...</td> </tr> <tr> <td><a href="#">Load additional rows</a></td> <td>Some data...</td> <td>Some data...</td> </tr> </tbody> </table> 

  • "send ajax request" - where? - Igor
  • @Igor should be sent! = Is sent. Imagine that the meter that is passed in after was obtained using ajax. I do not ask to write code for me, I am only interested in the way to associate an object with an asynchronous callback. - ilyaplot

1 answer 1

 success: (function(data){ // "this" here is target element of click event }).bind(this),