I am attempting to set a variable inside the success callback of an AJAX call. I understand that in order to assign the value, I need to use a callback function. However, I want that function to be within the class. Is it feasible to implement something like this?
function CallManagementClass() {
this.room_id = 'Error';
this.assignRoomVar = function(room_id) {
alert();
this.room_id = room_id;
}
this.getRoomID = function() {
$.ajax({
url: "/get_room_id.php",
dataType: "json",
success: function(data) {
this.assignRoomVar(data.room_id);
}
})
}
}
Is there a way to use bind? I attempted:
success: function(data) {
(function() { this.assignRoomVar(data.room_id); }).bind(this);
}
Although I do not encounter any errors, the function does not appear to be executed.