var memberURL;
var memberAva;
var memberName;
var members = data.find('.userdata');
for (var j = 0; j < members.length; j++) {
membername = $(members[j]).find('.username').text();
memberURL = $(members[j]).find('.username').attr('href');
}
memberAva = $('#advanced-profile-right img:eq[0]');
$.ajax({
url:"/viewonline",
type:"GET",
data: {memberURL, memberName}, //What should i do here?
success: function() {
$.ajax({
url: memberURL,
type:"GET",
data: memberAva
}).done(function() {
$('.user_info_on').append('<div class="on_name"><a href="' + memberURL + '" title="'+ memberName +'"><img src="' + memberAva + '"/></a></div>');
}
});
});
我试图从第一个 ajax 请求中得到的是成员 URL 和成员名称 - 然后在成功时向成员 URL(每个)发出另一个 ajax 请求并获取成员头像。然后在完成后发布检索到的数据。代码不工作,不知道我应该怎么做?
我尝试在两个 .get() 上发帖,但我想这是唯一的方法?无论如何,有人对我有建议和提示吗?
.get() 有效-
$(function () {
$.get('/viewonline', function (data) {
data = $(data);
var members = data.find('.userdata');
for (var j = 0; j < members.length; j++) {
var membername = $(members[j]).find('.username').text();
var memberURL = $(members[j]).find('.username').attr('href');
});
$('.user_info_on').append('<div class="on_name"><a href="' + memberURL + '" title="'+ membername +'"><img src=""/></a></div>'); //In between source of image would be memberAva from the other .get() request.
}
}, 'html');
});