On success, jQuery Ajax call object method?
-
Can you somehow run jQuery Ajax from within the object and pass a method of the same object to success?
With a simple example:
class Popup { Load(url) { $.get(url, this.SomeMethod); } SomeMethod(result) {} } var P = new Popup(); P.Load("/url");
JavaScript Anonymous, Jun 28, 2020 -
class Popup {
Load(url) {
const _this = this;
$.ajax(url, {
success: function (data) {
_this.SomeMethod(data);
}
});
}
SomeMethod(result) {
console.log(result);
}
}
const P = new Popup();
P.Load('https://qna.habr.com/q/883801#answers_list');Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!