Start a new topic

Query response is undefined

Hi, it is of course a little stupid error i cant find... I have a collection named "**tokens**" with "_prop_" and "_token_" columns.

this function:


function validateToken(){

var tokenfield =document.getElementById("tokenField").value;

var query = new Kinvey.Query();

query.equalTo('token', tokenfield);

var promise = Kinvey.DataStore.find('tokens', query, {

success: function(response) {

console.log("risposta " + response.prop );

window.localStorage.setItem("opponent",response.prop );

$.mobile.changePage('#game'); //change page





gives a log: "risposta undefined"

How can I access the data?

You are getting undefined for "response.prop" because response is an array. Since you are querying with the _find_ method(as opposed to _get_) your response will be an array of records, not a single record. If you are positive you will only be getting back a single record, then just do **response[0].prop** instead.
Oh thanks.. I knew it was a simple mistake.
Login or Signup to post a comment