How to retrieve data via JSONP with dynamic IDs?
Here's an example of how the API works from a third party provider.
https://app.example.com/api/head/category.json?_authbykey=56a7d8c531231c4058361687&_fields[]=name&id[$in][]=56d0b73131231c210d494e3e&id[$in][]=570fa55491231c001d4aeb98&id[$in][]=570fa55f12331cdf3d804b86&id[$in][]=570fa56d32123ce53f804ab0
I gathered all my IDs into a variable "parentIDs" and below is my code thus far.
- $.getJSON('https://app.example.com/api/head/suggest.jsonp?', {
- _authbykey: "56a7d8c531231c4058361687",
- _fields: ["name"],
- id:{
- "$in":[parentIDs]
- },
- callback: "?"
- }, function(dataParent) {
- refineSearch = "<fieldset><legend>Refine your search</legend>";
- $.each(dataParent.data, function(i, parent) {
- refineSearch += '<input type="checkbox" name="animal" value="' + parent.id + '" />' + parent.name + '<br />';
- console.log(parent.name);
- });
- refineSearch = "</fieldset>";
- });
I'm not getting even a console.log in this code. My guess it has something to do with the ID parameter. In the Params, this is what it showed:
_authbykey=56a7d8c531231c4058361687
_fields[]=name
callback=?
id[$in][]="56d0b73131231c210d494e3e","570fa55491231c001d4aeb98","570fa55f12331cdf3d804b86","570fa56d32123ce53f804ab0"
Any help is much appreciated.