내부 each
때문에, this
는 이상 반복되는 현재 요소 (docs), 그래서 일반적으로 우리가 전자 전에 뭔가 다른 것으로 this
을 정의로 설정 each
루프 nter :
var that = this;
$.each(response, function(index, val) {
var content = '<div class="link-history">'+ val.date + ', ' + val.userid + ', ' + val.status + '</div>';
$(that).parent().parent().append('foo');
});
그러나 이 상황은 Ajax 요청의 success
콜백에서 this
때문에, 요청하지 당신이 후하고있는 DOM
요소를 발사 jqXHR
개체와 같은지 var that = this
을 더 멀리 이동해야합니다.
var that = this;
$.ajax({
type: 'GET',
dataType: 'json',
cache: false,
url: 'barfoochakalaka',
success: function(response) {
$.each(response, function(index, val) {
var content = '<div class="link-history">' + val.date + ', ' + val.userid + ', ' + val.status + '</div>';
$(that).parent().parent().append('foo');
});
}
})
$ (this)의 체크 값 – sathis
'this'가 무엇을 원합니 까? – Joe
전에 오류가 발생하기 때문입니다. 오류 메시지가 무엇인지 확인하려면 자바 스크립트 콘솔을보십시오. – Hogan