简体   繁体   English

Parse.com:未定义用户

[英]Parse.com: user is not defined

I'm using parse.com as a back end for a web app. 我正在使用parse.com作为Web应用程序的后端。 I have a user that I have signed in to the app, and when the user is signed in to the website, I want their name to appear on every page in the website. 我有一个已经登录该应用程序的用户,并且当该用户登录网站时,我希望他们的名字出现在网站的每个页面上。

Here is my code for trying to recognize the username of the user: 这是我的代码,用于尝试识别用户的用户名:

// user logs on and is redirected to this page
var user = Parse.User.current();
user.on('change', function () {
console.log(user.get("username"));
});
user.fetch();

However, when I check the console, the error 但是,当我检查控制台时,错误

Uncaught ReferenceError: user is not defined

is present. 存在。

In my research, I've modified the code from Unable to get User's data . 在我的研究中,我修改了Unable的代码以获取User的数据 However, in my case, this code is not working. 但是,就我而言,此代码不起作用。

Any help is greatly appreciated! 任何帮助是极大的赞赏!

Try this: 尝试这个:

var user = Parse.User.current();
user.fetch().then(function(fetchedUser){
    var name = fetchedUser.getUsername();
}, function(error){
    //Handle the error
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM