Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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

share|improve this question
    
stackoverflow.com/a/13760360/356380 –  Whisher Nov 1 '14 at 20:39
    
make sure to check github.com/mgonto/restangular ;) –  deadlock Nov 1 '14 at 23:09

1 Answer 1

up vote 1 down vote accepted

'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);
});
share|improve this answer
    
Thank you 'theJoeBiz'. Well explained. I tried this and its worked :) –  Ajil Mohan Nov 2 '14 at 4:36

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.