user3353392
user3353392

Reputation:

Unable to retrieve required object from parse.com User class using javascript

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

Upvotes: 2

Views: 829

Answers (2)

Wesley Smith
Wesley Smith

Reputation: 19571

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");

Upvotes: 0

Marius Waldal
Marius Waldal

Reputation: 9942

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.

Upvotes: 0

Related Questions