dimanche 25 décembre 2016

How to access the correct `this` inside a callback for AJAX call?

I am unable to access 'this' in callback function but i end up using 'this' pointing to AJAX object rather than 'this' object who invoked onClickEmail function. I tried getting the reference in 'that' variable but that didn't helped much either. Anything I am doing wrong here:

onClickEmail(){
    var that = this;
    $.ajax({
            url: 'http://ift.tt/2i4O5zw'
        }).then(function(response) {
            hey = that;
        });
}




Aucun commentaire:

Enregistrer un commentaire