0

I am playing around with Parse Server and Node.js at the Moment and I am not very good in it. So i tried to make a call to my Parse Server from the Client.

Client Code:

$(document).ready(function () {
  $.ajax({
    type: 'GET',
    url: '/usernames',
    success: function (result) {
      console.log(result);
    }
  })
})

Code in my main.js :

app.get('/usernames', function (req, res) {
  var Userquery = new Parse.Query('Gamescore');
  var namearray;
  Userquery.find().then(function (results) {
    for (name in results) {
      namearray[name] = results[name].get('playerName');
    }
    res.success(namearray);
  })
})

So after I execute the Code nothing happen and i dont know why exactly.

Thank you for your help :)

  • `res.success()` doesn't exist. Try `res.send(JSON.stringify(namearray))` and you need to declare your `var namearray` as an object => `var namearray = {}`. – Fefux Dec 01 '16 at 09:05

1 Answers1

0

res.success belongs to ParseServer, useable in Parse Cloud like

Parse.Cloud.define('getUser',function (req, res) {
  let query = new Parse.Query('..');
  ...

  res.success(result); // or res.error(error)
})

where as your code is belongs to express route

app.get('/usernames', function (req, res) {
  let query = new Parse.Query('..');
  ...

  res.json(result);
})
Simon
  • 1,426
  • 3
  • 16
  • 24