jquery ajax calls with scope safety

Posted by acidzombie24 on Stack Overflow See other posts from Stack Overflow or by acidzombie24
Published on 2010-05-31T09:06:01Z Indexed on 2010/05/31 9:43 UTC
Read the original article Hit count: 171

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery