이 아약스 호출이 클래스가 있습니다 :Jquery ajax : 설정 범위 전달
this.__type = "PersonDto:#Empower.Service.Common.Dto"; this.Name = undefined; this.Surname = undefined; this.GetById = function (id) { return $.ajax({ type: "POST", url: "/Services/PersonService.svc/GetPersonById", data: JSON.stringify(id), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { ... this = data; ... } }); } };
this.__type = "PersonDto:#Empower.Service.Common.Dto"; this.Name = undefined; this.Surname = undefined; this.GetById = function (id) { return $.ajax({ type: "POST", url: "/Services/PersonService.svc/GetPersonById", data: JSON.stringify(id), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { ... this = data; ... } }); } };
아약스 호출의 성공 나는 사람의 현재 인스턴스를 설정하려면하지만 "이" 설정 범위가 정확하지 않습니다. 전역 변수를 사용하는 것보다 더 우아한 방법이 있습니까?
미리 도움을 주셔서 감사합니다. 나쁜 영어로 사과드립니다.
스코프 문제에도 불구하고, 당신은 덮어 쓸 수 없습니다'this' – Alnitak