나는 정말 이해가 안 :자바 스크립트 AJAX와 콜백
Calendar = function() {
this.data;
this.init = function(path, callback){
$.ajax({
url:path,
type:'GET',
success:function(data){
this.data = data;
console.log(this.data);
callback();
}
})
}
this.create = function(){
this.generateYear();
}
this.generateYear = function(){
console.log(this.data);
}
}
그리고는 다음과 같이 사용 :
$(document).ready(function(){
var calendar = new Calendar();
calendar.init(path,function(){
calendar.create();
});
});
그래서 첫 번째 콘솔. 로그는 좋지만 두 번째 것은 정의되지 않았기 때문에, 나는 그가 왜 호출 되었기 때문에 이해하지 못한다. 당신이 아약스에게주는 콜백에서 당신의 도움이
중복 가능성 [AJAX를 호출의 응답을 반환하는 방법?] (http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an- ajax-call) – elclanrs
@elclanrs –
첫 번째'console.log (this.data); 다음에'callback();'이 무엇입니까? – Paritosh