I have an AJAX call, where I use a variable bound to this
in my URL call. I also need this in the callback.
Initially I was using the var _that = this
pattern, but that didn't pass code review. I threw in the context: this
, but unsure if it works on that second link, where I need to actually access this or if it's only available in the callback.
Question:
What is the cleanest approach for accessing the this
context variable to use in the url
param and also the callback?
$.ajax({
url: "/search/".concat(_this.options.modelId),
contentType: "application/json; charset=utf-8",
dataType: "json",
type: 'PUT',
data: JSON.stringify(templatePerms),
context: this,
success: function(data) {
this.message('Success!', 'Updated', 'success');
this.cleanup();
}
});