gpt4 book ai didi

javascript - 为什么我得到 : Uncaught ReferenceError: response is not defined

转载 作者:行者123 更新时间:2023-11-30 19:18:18 28 4
gpt4 key购买 nike

为什么我得到这个?我该如何解决?我对编码相当陌生:我试图修复它,但我不知道如何:这是代码:

我已经尝试了所有我知道的方法,不幸的是我的知识非常匮乏,我自学了所有东西所以我并不完全了解所有行话,该网站是 beatsbycayde.com,基本上我试图能够获得 Angular 色 ID,这样我就可以用它链接到 braytech.org/2/{destinyid]/{characterId}/legend

    // get list of members and populate roster table

var roster = [];

$.when(
$.ajax({
url: "https://www.bungie.net/platform/GroupV2/699392/Members/",
headers: {
"X-API-Key":"47b810e692d64237911c2cbe0d433cfe"
}
})
.success(function(json) {

if (json.ErrorStatus === 'Success') {

roster = json.Response.results;

console.log('Exalted member list:', roster);

} else {

alert('Uh oh, looks like Bungie\'s doing server maintenance or having problems. Please check back again soon!');
console.log(json);

}

})
.error(function(json) {

alert('Uh oh, looks like Bungie\'s doing server maintenance or having problems. Please check back again soon!');
console.log(json);

}),

$.ajax({
url: 'https://www.bungie.net/platform/destiny2/2/profile/4611686018429000034/?components=200',
headers: {
'X-API-Key': "47b810e692d64237911c2cbe0d433cfe"
}
}).success(function(res) {
console.log('PS4 stats:', res);
})

)
.then(function() {

listMembers(roster);

});

function listMembers(rsp) {

var
list = $('.memberList-list'),
on = 0,
sortMembers = function(method) {
// sort by date joined
if (method = joined) {
list.find('.member').sort(function(a, b) {
return ($(b).data('joined')) < ($(a).data('joined')) ? 1 : -1;
}).appendTo(list);
} else if (method = username) {
list.find('.member').sort(function(a, b) {
return ($(b).data('username')) < ($(a).data('username')) ? 1 : -1;
}).appendTo(list);
}
list.find('.member.online').prependTo(list);
};

for (var i = 0; i < rsp.length; i++) {

var
profile = rsp[i].bungieNetUserInfo,
member = $('<a></a>');

// tally up online members
if (rsp[i].isOnline) {
on++
}

// check for valid profile
// some users don't have Bungie profiles somehow and it breaks function
if (typeof profile != 'undefined') {
// store response data in semantic variables
var
name = rsp[i].destinyUserInfo.displayName,
joinDate = rsp[i].joinDate,
joined = joinDate.substring(0, joinDate.indexOf('T')),
online = rsp[i].isOnline,
icon = profile.iconPath,
memberId = profile.membershipId,
memberType = rsp[i].destinyUserInfo.membershipType,
destinyId = rsp[i].destinyUserInfo.membershipId,
rank = rsp[i].memberType;
// configure D OM node and add to page
$('#destiny-Id').text(destinyId);

member
.attr({
'class': 'j-row vertical-center-row member',
'href': '/player/?bungieId=' + memberId + '&destinyId=' + destinyId + '&joined=' + joined + '&rank=' + rank,
'title': 'See player profile for ' + name,
'data-joined' : joined.replace(/-/g, ''),
'data-username': name,
'data-online' : 'false',
'data-searchable' : name,
})

$.ajax({
url: "https://www.bungie.net/Platform/Destiny/2/Account/"+ destinyId +"/",
headers: {
"X-API-Key":"47b810e692d64237911c2cbe0d433cfe"
}
})
.success(function(response) {

if (data.ErrorStatus === 'Success') {

depth = response.data;

console.log('Exalted member list:', roster);

} else {

alert('Uh oh, looks like Bungie\'s doing server maintenance or having problems. Please check back again soon!');
console.log(json);

}
//have the line here
var
CharacterId = depth.characters.characterbase.characterId;
})
.html(
'<div class="j-col j-col-1 member-icon"><img src="https://bungie.net/' + icon + '"></div>' +
'<div class="j-col j-col-3 member-name"><h3>' + name + '</h3></div>' +
'<div class="j-col j-col-3 member-joined" data-label="Joined">' + joined.replace(/-/g, '/') + '</div>' +
'<div class="j-col j-col-3 member-status" data-label="Status"><span class="member-online" id="status-' + memberId + '">' + online + '</span></div>' +
'<div class="j-col j-col-3 member-button"><a class="button outline gold full-width">' + 'View Stats' + '</a></div>'+
'<div class="j-col j-col-3 members-button"> + <a href="https://braytech.org/2/'+ destinyId +'/' + CharacterId +' /legend">In Depth Stats</a>' + '</a></div>'
);

if (rsp[i].exalted) {
member.addClass('exalted')
.attr({
'href': '/player/?bungieId=' + memberId + '&destinyId=' + destinyId + '&joined=' + joined + '&rank=' + rank + '&exalted=false'
})
.find('.member-name').find('h3')
.html(name + ' &nbsp;<span class="gold" title="Exalted">&epsilon;</span>');
}

member.appendTo(list);

// indicate online/offline status
if (String(online) === 'true') {
$('#status-' + memberId)
.text('Online')
.addClass('online')
.closest('.member')
.attr('data-online', true)
.addClass('online');
} else {
$('#status-' + memberId).text('Offline').removeClass('online');
}

sortMembers(joined); // sort members by join date

}

}

$('#member-count').text(on + ' / ' + rsp.length + ' Members Online');

}

最佳答案

这一行:

var CharacterId = response.characters.characterbase.characterId;

不在 function(response) { ... } block 内,因此它无权访问 response 变量,因此出现“未定义”错误.

尝试将此行插入 block 内。

编辑:我的意思是:

.success(function(response) {

if (json.ErrorStatus === 'Success') {

response = response.data;

console.log('Exalted member list:', roster);

} else {

alert('Uh oh, looks like Bungie\'s doing server maintenance or having problems. Please check back again soon!');
console.log(json);

}
//have the line here
var CharacterId = response.characters.characterbase.characterId;
})

//not here
var CharacterId = response.characters.characterbase.characterId;

关于javascript - 为什么我得到 : Uncaught ReferenceError: response is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57760077/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com