1

New to jquery/php i have a script i'd like to improve :

I am using TCPDF to generate a pdf that i output via 'F' option locally on my server and sending a simple json response (path/file) to display the pdf in a bootstrap modal (using an iframe).

It's working great but i'd like to send the pdf with 'S' or 'I' option as a binary stream so that i dont have to deal with the file afterward (clean.php to delete the file).

Is this even possible?

Thank you for your help :)

$.ajax({
            url: "./../app/renders/pdf_render.php",
            type: "POST",
            timeout: timeout1,
            data: {                           
                id: id_p
            },
            dataType: 'json',
            success: function(json){
                if(json.result == 1){ // OK
                    $("#frame_q").attr("src","../../public/tmp/"+json.file);
                    // cleaning pdf... doesnt always work with edge
                    $.ajax({
                        url: "./../app/renders/clean.php",
                        type: "POST",
                        timeout: timeout1,
                        data: {                           
                            file: json.file 
                            },
                        dataType: 'json'
                    });
                }else{ // NOK
                    switch(json.result){
                        case '0' :{  .....
Home
  • 43
  • 2
  • 6
  • The simplest way would be to change the request from POST to GET and set the url to the src attribute of the iframe. – Musa Jan 17 '18 at 14:50
  • @Musa Isnt there a dataType :binary or something like that so i could get the pdf as binary in success callback and then display it in modal? no other solution than GET? – Home Jan 17 '18 at 19:10
  • Well yeah, something like [this](https://stackoverflow.com/questions/17657184/using-jquerys-ajax-method-to-retrieve-images-as-a-blob/17682424#17682424) – Musa Jan 17 '18 at 19:17

0 Answers0