0

I have this plunker

http://plnkr.co/edit/ml1Eqvz5pZY1MgxX87s7?p=preview

i am trying to query the .json file with no success. here is my factory

app.factory('myService', function($http, $q) {
   return {
 getFoo: function() {
   var deferred = $q.defer();
   $http({ url: 'foo.json', 
    method : "GET", 
    params : { 'item.id' : 0 } })

   .success(function(data) {
      deferred.resolve(data);
   }).error(function(){
      deferred.reject();
   });
   return deferred.promise;
 },

   }
 });

it works well but it doesn't get only the id:0. I want not to load all data from the .json file. I want to load only what's in id:0

any pointers?

thank you

2
  • @JBNizet In fact, what he has is just a static json file, and he is expecting http parameters to be the magic data filter ;) Commented May 8, 2014 at 20:42
  • @YeLiu: yes, I realized after posting my comment that this was indeed the case. Commented May 8, 2014 at 20:44

1 Answer 1

1

What you have is a static JSON file. You can add every parameter you want to the request, if there is no dynamic component at server-side to interpret these parameters and serve what you want to serve, sending parameters is useless: the server receives a request for a static JSON file, and it serves the static JSON file.

Sign up to request clarification or add additional context in comments.

4 Comments

I see, I didn't know that. is there any way to query a static json file?
Not using http. You'll have to download it, and filter it using JS code. In a real app, JSON is typically dynamically generated from the parameters of the query, by loading the requested data from a database and transforming it to JSON.
thank you. my json file is apprx 40MB and I won't need all the data everytime. it would be waste of time to load all of it and filter it on the client. if i want to query the 40MB of data is my only option to put it in a database?
No, not necessarily in a database. What matters is that you need a server-side API that generates JSON dynamically. How it does it is irrelevant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.