아래 코드를 실행하면 "uncaught TypeError : undefined is not function"이라는 줄이 "back.ajax ({". jQuery 문서 및이 트릭을해야합니다 것 같아요. 또한 jQuery 포함되어 있고 브라우저가 "$"인식합니다 .CURRYEAR 정의 된 및 모든 요소가 참조 된.이 콜백 같은 코드를 사용하는 경우 .load() 다음 그것을 잘 실행,하지만 난 비동기 적으로 호출하는 경우 while 루프는 한 번만 실행으로 동 기적으로 실행해야익명 함수는 콜백에서 "정의되지 않음이 함수가 아닙니다"라고 알려줍니다.
코드 :.
function loadWL() {
var back = $("#back-results");
var numYears;
var year;
var count = 0;
var wArr = [];
var lArr = [];
var dArr = [];
do {
year = CURRYEAR - count;
var standingsURL = STANDINGS.replace(" ", localStorage["leagueID"]);
standingsURL = standingsURL.replace(",", year);
var yqlStand = 'https://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + standingsURL + '"') + " #maincontainertblcell";
//Load into the hidden pane
var id;
var self = this;
back.html("");
back.ajax({
url: yqlStand,
async: false
}).done(function() {
//Parse the number of years the league has been active
if (count == 0) {
numYears = $("select > option").length;
}
//Narrow to only the elements we need
$(self).html($("#back-results tr .tableBody"));
//Now traverse the back pane and store info
$("#back-results > .tableBody a").closest("tr").each(function(index) {
id = urlToID($(this).find("a").attr('href'));
if (typeof wArr[id] == 'undefined') {
wArr[id] = 0;
lArr[id] = 0;
dArr[id] = 0;
}
wArr[id] = wArr[id] + parseInt($(':nth-child(2)', this).text().trim(),10);
lArr[id] = lArr[id] + parseInt($(':nth-child(3)', this).text().trim(), 10);
dArr[id] = dArr[id] + parseInt($(':nth-child(4)', this).text().trim(), 10);
if (count == numYears-1) {
arrayToLocal(wArr, "wins");
arrayToLocal(lArr, "losses");
arrayToLocal(dArr, "draws");
}
});
count++;
return;
});
} while (count < numYears);
}
입력 해 주셔서 감사합니다. 로드 할 페이지 수를 찾기 위해로드를 끝내고 큐에 넣은 다음 콜백에서로드되고 재귀 적으로 자신을 호출하는 함수를 호출합니다. 페이지의 직렬로드를 허용합니다. – PapaHenry