jquery ajax calls with scope safety
- by acidzombie24
My gut tells me that if i am on a laggy server and the user fires two events fast enough on the success function c will be the value of the most recent event causing func1 to use the wrong value. <--- This is a guess, i haven't proved it. Its a feeling.
How do i ensure that i use the right value when calling func1? I prefer not to send c to the server and i dont know if or how to serialize the data and deserialize it back. How do i make this code safe?
$('.blah').click(function (event) {
var c = $(this).closest('.comment');
...
$.ajax({ url: "/u", type: "POST", dataType: "json", data: { ... },
success: function (data) {
func1(c. data.blah);//here