javascript - Problems making ajax call for json data from Statistics Sweden public API -


hoping identifying problem ajax call statistics sweden (scb).
scb api instructions here

i can table metadata (step 4.3 in instructions) below call

$.ajax({     url: "http://api.scb.se/ov0104/v1/doris/en/ssd/be/be0401/be0401b",     type: "post",     datatype: 'json',     success: function(response) {         console.log(response);     },     error: function(xhr) {         console.log(xhr.statustext)     } }); 

but, receive 404 error not found, when trying below query table post request.
(example taken step 4.4 in instructions - bottom half of page 7 of pdf)

or if try request, get table metadata , no results

$.ajax({     url: "http://api.scb.se/ov0104/v1/doris/en/ssd/be/be0401/be0401b/befprogfoddamedel15",     data: {         "query":             [{"code":"fodelseland", "selection":{"filter":"item",            "values":["010","020"]}},            {"code":"alder", "selection":{"filter":"all", "values":["*"]}},            {"code":"tid", "selection":{ "filter":"top", "values":["3"]}}],          "response": {"format":"json"}     },     type: "post",  // returns table metadata     datatype: 'json',     success: function(response) {         console.log(response);     },     error: function(xhr) {         console.log(xhr.statustext)     } }); 

edit
added tried request returns table metadata , not statistics

solution
call json.stringify on query data before posting.
code posted below petros likidis

i no expert in javascript have had same problem. solved converting json query (the post data) string calling json.stringify see

http://jsbin.com/punaveteke/edit?js,console,output

$(document).ready(function () {      $.ajax({         type: "post",         url: "http://api.scb.se/ov0104/v1/doris/en/ssd/be/be0401/be0401b/befprogfoddamedel15",         data: json.stringify({             "query": [{                 "code": "fodelseland",                 "selection": {                     "filter": "item",                     "values": ["010", "020"]                 }             }, {                 "code": "alder",                 "selection": {                     "filter": "all",                     "values": ["*"]                 }             }, {                 "code": "tid",                 "selection": {                     "filter": "top",                     "values": ["3"]                 }             }],             "response": {                 "format": "json"             }         }),         datatype: "json",         success: function (response) {             console.log(response);         },         error: function (xhr) {             console.log(xhr.statustext)         }     }); }); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -