jquery - how to pass the param in $.ajax to be filtered in json? -


 var type = $(this).attr('id');     $.ajax({           type: 'get',           url: 'path/to/example.json',           datatype: 'json',           data: {type: "type"} //not working?           ......      { 

json

  "name": "jh",   "type": "zoologist, hobbyist" }, 

html

   <div class="filter">           <a href="?type=all" id="all">view all</a>           <a href="?type=zoologist" id="zoologist">zoologist</a>           <a href="?type=hobbyist" id="hobbyist">hobbyist</a>           <a href="?type=judge" id="judge">judge</a>       </div> 

not familiar $.ajax , frustrated quite long while, trying pass param filter type in json.

filter link clicked on , attribute of id. want pass id data: {type: type}.

wanted retrieve details of same type filtered

not understand why not doing anything. or not possible filter type in json?

obviously better filter data before sending client, according comments didn't use/want server side code.

so, using js, return whole data-set , filter it:

 $.ajax({     type: 'get',     url: 'path/to/example.json',     datatype: 'json',     success: function(response) {         console.log('success, filtering response...');          //filter returned json "filter"                     var filteredjson = $(response).filter(function (i,n) {              return n.type === $('#someid').attr('id');          });          //... more code     }  }); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -