Reputation: 2196
I'm attempting to fetch the currentuser's username, and have it displayed on screen, here is my code:
Parse.User.logIn(username, password, {
success: function(user) {
var currentUser = Parse.User.current();
currentUser.fetch().then(function(fetchedUser) {
var name = fetchedUser.getUsername();
});
$('.alertmsg').html('<div id="alert"><p>You are' + name + '</div>');
}
});
Everything is working fine, but the username won't display.
Hope that this is an easy fix!
Upvotes: 0
Views: 3365
Reputation: 31590
You should move the line at which you update the html of alertmsg
in the callback, that is because name
is scoped to the callback function and does not exist outside of it:
Parse.User.logIn(username, password, {
success: function(user) {
var currentUser = Parse.User.current();
currentUser.fetch().then(function(fetchedUser) {
var name = fetchedUser.getUsername();
$('.alertmsg').html('<div id="alert"><p>You are' + name + '</div>');
});
}
});
Upvotes: 5