이 코드가 있습니다jQuery에서 콜백 함수의 반환 값은 무엇입니까?
function dialogTexts(message) {
var langText = $.ajax({
type: 'GET',
url: '/index.php/main/dialogtexts',
dataType: 'json'
});
langText.done(function(data) {
message(data);
});
langText.fail(function(ts) {
alert(ts.responseText);
});
}
dialogTexts(function(text) {
alert(text.delete);
});
내가 (위의 코드에서) 문자열 text.delete을 경고하기 위해 콜백을 사용하고,하지만 내가 좋아하는 뭔가를하고 싶지 :
dialogTexts(function(text) {
return text;
});
var deleteConfirmationDialogText = dialogTexts.delete;
alert(deleteConfirmationDialogText); //deleteConfirmationDialogText is undefined
"콜백 외부의 데이터에 액세스 할 수없는 이유는 무엇입니까?"- 질문은 현재 가장 일반적인 것입니다. – Johan