Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I'm using the JavaScript SDK with I'm using parse.com.

The below code is meant to select the user thats currently logged in, then retrieve their "username" from the "User" class and show it in the console log.

Parse.initialize("XXXX", "XXXX");
var currentUser = Parse.User.current();    
var query = new Parse.Query(Parse.User);
query.equalTo(currentUser);  
query.find({
  success: function(theuser) {
    console.log(username);
  }
});

UPDATE, BASED ON THE ANSWER BELOW I TRIED

var currentUser = Parse.User.current();
var user = currentUser.get("username");
var user = currentUser.get("gender");
   console.log(user); 
   console.log(gender); 

but now get Uncaught ReferenceError: gender is not defined ?


At the moment I'm getting the following error.

POST https://api.parse.com/1/classes/_User 400 (Bad Request) parse-1.2.17.min.js:1 t._ajax parse-1.2.17.min.js:1 t._request parse-1.2.17.min.js:1 t.Query.find parse-1.2.17.min.js:3 (anonymous function)

This seems to say it cannot find the User class, but you can see from the screen shot this does exist. Can anyone help me with what the issue is here?

parse backend

screen shots

share|improve this question

2 Answers 2

With "var currentUser = Parse.User.current(); " you already have the current user object. Don't query for it. Just get the value from the object.

share|improve this answer
    
Thanks, I've updated the code your answer if you can just help answer the point I've raised I will accept your answer. – user3353392 Mar 29 '14 at 13:44
    
Besides the fact you're declaring var user twice, the screenshot does not show the user class having a gender field. Gender is not defined since you specified user instead of gender, I assume... – Handsomeguy Mar 29 '14 at 16:12

One problem is here:

var user = currentUser.get("username");
var user = currentUser.get("gender"); //you also named this var 'user' instead of 'gender'

change this to:

var user = currentUser.get("username");
var gender = currentUser.get("gender");
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.