Saturday, 15 August 2015

ajax - How to get a file(pdf) via json API call? -



ajax - How to get a file(pdf) via json API call? -

my search reply keeps getting interfered because of pdf keyword.

i'm trying fetch document via api call. see below:

(function($) { // handles opening notes list page displaydocument = function(documentpath) { console.log("reached displaydocument"); var callapi = documentpath; console.log(callapi); var documentreq = $.ajax({ beforesend: function() { showloader(); }, url: callapi, datatype: 'json', contenttype: 'application/pdf', headers: { authorization: 'token ' + authtoken } }); documentreq.success(function(data) { console.log("got resume " + data); }); documentreq.error(function(data) { console.log("failed resume " + json.stringify(data)); }); }; })(jquery);

i 200 ok back, request goes "error".

documentreq.error function starts spitting out this:

failed resume {"readystate":4,"responsetext":"%pdf-1.4\r\n%����\r\n1 0 obj\r\n<<\r\n/type /catalog\r\n/pages 2 0 r\r\n>>\r\nendobj\r\n3 0 obj\r\n<<\r\n/creationdate (d:20060515092800)\r\n/author (aaronb)\r\n/creator (ikon communications)\r\n/producer (ikon communications)\r\n/title (aaron w)\r\n>>\r\nendobj\r\n2 0 obj\r\n<<\r\n/type /pages\r\n/kids [4 0 r 5 0 r]\r\n/count 2\r\n/resources <<>>\r\n\r\n/mediabox [.00 .00 595.00 842.00]\r\n>>\r\nendobj\r\n4 0 obj\r\n<<\r\n/count 1\r\n/type /pages\r\n/kids [6 0 r]\r\n/parent 2 0 r\r\n/mediabox [.00 .00 612.00 792.00]\r\n>>\r\nendobj\r\n5 0 obj\r\n<<\r\n/count 1\r\n/type /pages\r\n/kids [7 0 r]\r\n/parent 2 0 r\r\n/mediabox [.00 .00 612.00 792.00]\r\n>>\r\nendobj\r\n6 0 obj\r\n<<\r\n/type /page\r\n/parent 4 0 r\r\n/contents [8 0 r]\r\n/resources <<\r\n/procset [/pdf /imageb /imagec /imagei /text]\r\n/xobject <<\r\n/ed12522b-184c-403b-ba19-aba6d7723557 9 0 r\r\n>>\r\n\r\n>>\r\n\r\n>>\r\nendobj\r\n7 0 obj\r\n<<\r\n/type /page\r\n/parent 5 0 r

so figure i'm missing how handle document itself, compared normal json phone call key: "value"s

any thoughts? or directions?

cheers in advance

ajax json api get

No comments:

Post a Comment