I have a variable declared inside a function and the same function also contain code for an ajax call. Now I want to access that variable inside the .done
,fail
& always
function of this promise
. But on consoling inside done
it is logging undefined
// Rest of code
click:function(event){
var getTrtCode = "someVar";
var makeCall = $.ajax({
url:"someUrl"
})
makeCall.done(function(response){
console.log(" ******* "+getTrtCode);
})
.always(function(){
})
}
EDIT
I dont want to make getTrtCode
a global variable