1

My search for this answer keeps getting interfered with because of the pdf keyword.

I'm trying to fetch a document via an API call. See below:

(function($) {  // Handles opening a 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 to get resume " + JSON.stringify(data));
    });
};
})(jQuery);

I get 200 OK back, the request goes to "error".

documentReq.error function starts spitting out this:

Failed to get 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 I figure I'm just missing something with how to handle the document itself, compared to a normal json call with Key: "value"s

any thoughts? or directions?

cheers in advance

1
  • 2
    Your datatype surely is not json
    – leppie
    Feb 17, 2013 at 2:59

0

Your Answer

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

Browse other questions tagged or ask your own question.