Метод jQuery.ajax()
[документы] дает вам свойство context
, где вы можете установить значение this
в обратных вызовах.
Просто сделай:
context: this,
... в вашем вызове, как в:
this.GetById = function (id) {
return $.ajax({
type: "POST",
context: this, // <---- context property to set "this" in the callbacks
url: "/Services/PersonService.svc/GetPersonById",
data: JSON.stringify(id),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// in here, "this" will be the same as in your "getById" method
}
});
}