Parse.com:用户未定义(Parse.com: user is not defined)

编程入门 行业动态 更新时间:2024-10-13 00:31:48
Parse.com:用户未定义(Parse.com: user is not defined)

我正在使用parse.com作为网络应用的后端。 我有一个用户已登录该应用,当用户登录该网站时,我希望他们的名字出现在网站的每个页面上。

以下是我尝试识别用户用户名的代码:

// 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();

但是,当我检查控制台时,错误

Uncaught ReferenceError: user is not defined

存在。

在我的研究中,我修改了Unable中的代码以获取用户的数据 。 但是,在我的情况下,此代码不起作用。

任何帮助是极大的赞赏!

I'm using parse.com as a back end for a web app. 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. However, in my case, this code is not working.

Any help is greatly appreciated!

最满意答案

尝试这个:

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

Try this:

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

更多推荐

本文发布于:2023-08-07 17:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未定义   用户   Parse   user   defined

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!