2

I'm learning AngularJS , i set-up a development environment using sublime-text as editor and parse.com-rest-api used as back-end layer.

I came across a scenario where, I have to fetch data based on an attribute.

Below given code from the service layer of angularjs has fetch all records from table 'filim'.

var config = {

                    headers: {
                        'X-Parse-Application-Id': 'bNtp8FUfr0s1UsAwJr7MFjabCI31HytIuC3gCaJ2',
                        'X-Parse-REST-API-Key': 'g18cAoH7QkrBZenPqH0pynMKsn6pj4MyfDyIy6X1',
                    }
                };

        return {
            getFilims: function(callback) {
                var filims;

                var resp = $http.get('https://api.parse.com/1/classes/filim', config).success(function(data) {

                    callback(data.results);
                });
            }
        }

I have modified above url to send query-parameter to filter the output, but did not work. I refer parse.com api doc [ https://www.parse.com/docs/rest#queries ] to modify url to send query - param.

Modified code is given below,

var params = {"where": {"status" : "CLOSED" } }

        var resp = $http.get('https://api.parse.com/1/classes/filim?%s' % params, config).success(function(data) {

            callback(data.results);
        });

But this did not work.

Is this the way to use query-parameter ?

Regards Ajil

Ajil Mohan
  • 7,299
  • 2
  • 18
  • 18

1 Answers1

1

'https://api.parse.com/1/classes/filim?%s' % params

This is a python pattern for interpolating strings and will not work in javascript.

The correct way of combining strings in javascript is:

'https://api.parse.com/1/classes/filim?' + params

Even still, that will probably not work because you'll end up with something like:

'https://api.parse.com/1/classes/filim?[Object object]

What you need to do for parse.com is to JSON encode the query, so try this:

var whereQuery = {"status" : "CLOSED"};
var url = 'https://api.parse.com/1/classes/filim?where=' + encodeURI(JSON.stringify(whereQuery));

var resp = $http.get(url, config).success(function(data) {
  callback(data.results);
});
Joe
  • 2,596
  • 2
  • 14
  • 11