아무도 나에게 빈 문자열을 제공하는 이유를 말해 줄 수 있습니까? $.get()
콜백 함수에있는 console.log(contentArray)
에 콜백 함수가 표시되면 데이터가 표시되지만 아래 코드의 위치에서 데이터를 표시하려고하면 결과가 비어 있습니다..get 호출에서 jQuery .push를 호출하면 빈 결과가 나타납니다.
sectionArray = [];
contentArray = [];
$(function() {
if (index == 1) {
$('menu:eq(' + (section - 1) + ') li a').each(function() {
sectionArray.push($(this).attr('href'));
});
var len = sectionArray.length;
for (var i = 0; i < len; i++) {
href2 = sectionArray[i];
$.get(href2, function (data) {
string = data.toString();
contentArray.push(string);
});
}
content = contentArray.toString();
console.log(content);
}
, $ 갔지 (href2, 기능 (데이터) { 내용 때문에 = contentArray.push (데이터); console.log (콘텐츠); }); 작품입니다. 제가 시도 $ 갔지 (href2, 기능 (데이터) = { 문자열 data.toString(); contentArray.push (문자열) }); 콘텐츠 = contentArray.toString(); console.log (content); 그러나 그것은 작동하지 않습니다 – Psylant
왜냐하면'.push()'가'console.log()'다음에갑니다. – Vytautas
여러 페이지에서 데이터를 수집 한 다음 1 페이지로 떨어 뜨려야하기 때문에 반복해야합니다 – Psylant