Why do object responses undefined?
-
31-05-2021 - |
Question
<script src="http://vkontakte.ru/js/api/openapi.js" type="text/javascript">
</script>
<div id="login_button" onclick="VK.Auth.login(getit);"></div>
<script language="javascript">
VK.init({
apiId: 2903251
});
function getit(response) {
if (response.session) {
var id = response.session.mid;
}
VK.Api.call('users.get', {uids: id, fields: 'sex,photo_big'}, function(r) {
if(r.response) {
alert(r.response.sex);
console.log(r.response);
}
});
}
VK.UI.button('login_button');
</script>
Why does alert(r.response.sex)
display undefined, but everything is OK with console logs?
Solution
Solved. The solution: r.response[0].sex
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow