Results 1 to 6 of 6

Thread: Download PDF from server

  1. #1
    Sencha User
    Join Date
    Dec 2013
    Posts
    65
    Answers
    2

    Default Answered: Download PDF from server

    Hello, i am have problem. I am sent to server request with array parameters,
    PHP Code:
     Ext.Ajax.request(                    
    {                        
    url'/getPdf',                       
     
    paramspdfParams,                       
     
    isUploadtrue,                       
     
    success: function (responseoptions) {                                           
     
    console.log('download complete');                       
     },                       
     
    failure: function (responseoptions) {                                           
     
    console.log('failure');                        
    }                   
     }); 
    and then server response to me error with text:

    Code:
    [E] [E] Ext.JSON.decode(): You're trying to decode an invalid JSON String: %PDF-1.4%????
    1 0 obj
    <<
    /Type /Catalog
    /Pages 4 0 R
    /MarkInfo<</Marked true>>
    /Metadata 11 0 R
    /OutputIntents 13 0 R
    /StructTreeRoot 5 0 R
    /PageMode /UseNone
    >>
    endobj
    
    
    2 0 obj
    <<
    /Producer (Stimulsoft Reports)
    /Creator (Stimulsoft Reports 2015.2.0 from 30 September 2015)
    /Subject (Report)
    /Title (Report)
    
    
    ...
    <<
    I am want if request to server do, then at once download file, but i am have this error,

  2. Quote Originally Posted by neosky View Post
    If i am want transfer parameters in very big array of objects, this way good ?
    You could turn a javascript object into a query string very easily like this:

    Code:
    var params = {
            'Name': 'Homer',
            'ID': 1,
            'Etc': null
        },
        url = '/getPdf?' + Ext.Object.toQueryString(params);

  3. #2
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,271
    Answers
    13

    Default

    You can't download a PDF using an Ajax request - it expects JSON or XML. To add a link to download something from the server (for the user to save somewhere), you could do this:

    PHP Code:
    // Add an Ext.component to your form, then add a "Process Config" as follows
    config.autoEl = {
        
    tag'a',
        
    href'/getPdf',
        
    html'Click here',
        
    target'_new'
    };
    return 
    config
    This is what I do in Ext JS 4 & 5. I haven't used 6 yet (waiting for Sencha Architect support! )

  4. #3
    Sencha User
    Join Date
    Dec 2013
    Posts
    65
    Answers
    2

    Default

    Quote Originally Posted by marc.fearby View Post
    You can't download a PDF using an Ajax request - it expects JSON or XML. To add a link to download something from the server (for the user to save somewhere), you could do this:

    PHP Code:
    // Add an Ext.component to your form, then add a "Process Config" as follows
    config.autoEl = {
        
    tag'a',
        
    href'/getPdf',
        
    html'Click here',
        
    target'_new'
    };
    return 
    config
    This is what I do in Ext JS 4 & 5. I haven't used 6 yet (waiting for Sencha Architect support! )
    very thanks for answer. With this solution I can pass parameters to the server in object?

  5. #4
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,271
    Answers
    13

    Default

    Quote Originally Posted by neosky View Post
    very thanks for answer. With this solution I can pass parameters to the server in object?
    Just pass the parameters to the server after the URL for the PDF (which I presume you're generating on-the-fly):

    PHP Code:
    /getPdf?param=value&something=else 

  6. #5
    Sencha User
    Join Date
    Dec 2013
    Posts
    65
    Answers
    2

    Default

    Quote Originally Posted by marc.fearby View Post
    Just pass the parameters to the server after the URL for the PDF (which I presume you're generating on-the-fly):

    PHP Code:
    /getPdf?param=value&something=else 
    If i am want transfer parameters in very big array of objects, this way good ?

  7. #6
    Sencha Premium User
    Join Date
    Sep 2011
    Location
    Tamworth, NSW, Australia
    Posts
    1,271
    Answers
    13

    Default

    Quote Originally Posted by neosky View Post
    If i am want transfer parameters in very big array of objects, this way good ?
    You could turn a javascript object into a query string very easily like this:

    Code:
    var params = {
            'Name': 'Homer',
            'ID': 1,
            'Etc': null
        },
        url = '/getPdf?' + Ext.Object.toQueryString(params);

Similar Threads

  1. Download word file from server using Ext-js 4
    By rakesh.mmp in forum Ext: Q&A
    Replies: 3
    Last Post: 15 May 2015, 12:23 AM
  2. Force download file from server
    By ezriel in forum Ext: Q&A
    Replies: 5
    Last Post: 23 Apr 2013, 3:05 AM
  3. How to call server code to download image
    By hcervantes in forum Ext: Q&A
    Replies: 1
    Last Post: 20 Mar 2012, 9:35 AM
  4. [SOLVED] how to download a server's file dynamically?
    By pirusira in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 5 Aug 2010, 6:40 PM
  5. Download a file from server using Ajax
    By bhuvhi in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 13 May 2009, 3:49 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •