我正在尝试从JSON URL中获取值并将其实现为HTML行。这是我的代码的一部分。
for (var i = 0; i < professorElementNode.length; i++) {
var fullName = professorsArray[i].first + professorsArray[i].last;
console.log(fullName);
var parentNode = professorElementNode[i].parentNode;
var childElement = document.createElement('a');
childElement.innerText = "hey"
parentNode.appendChild(childElement);
parentNode.appendChild(childElement);
childElement.href = "http://example.com";
var profrating = [];
var profUrl = 'https://search.mtvnservices.com/typeahead/suggest/?solrformat=true&rows=20&q=' + professorsArray[i].first + '+' + professorsArray[i].last + '+AND+schoolid_s%3A1262&defType=edismax&qf=teacherfirstname_t%5E2000+teacherlastname_t%5E2000+teacherfullname_t%5E2000+autosuggest&bf=pow(total_number_of_ratings_i%2C2.1)&sort=total_number_of_ratings_i+desc&siteName=rmp&rows=20&start=0&fl=pk_id+teacherfirstname_t+teacherlastname_t+total_number_of_ratings_i+averageratingscore_rf+schoolid_s&fq=';
Get(profUrl, function(err, data) {
profrating[i] = data.response.docs.map(doc => doc.averageratingscore_rf);
var pkID = data.response.docs.map(doc => doc.pk_id);
var ratingCount = data.response.docs.map(doc => doc.total_number_of_ratings_i);
childElement.innerText = profrating[i];
console.log(fullName, profrating[i]);
});
}
和here是插入html的页面以及控制台日志的屏幕截图。我知道ajax是异步的,但是解决方法是什么?