1

I have a list of bills in my table and each row has it's own unique bill (different date, amount etc...). I have successfully managed to make php call via Soap:Wrapper in Laravel 5 and when i type in browser "path to that procedure" i get my pdf. But i would like to open it using Javascript.

My code of server side

$pdfData= $soap->racun($data);

header("Content-type: application/pdf");
header("Content-Length:" . strlen($pdfData));

//this line if i want to preview my pdf in browser 
header("Content-Disposition: inline; filename=pdf.pdf");

//this line if i want to download my pdf
header('Content-Disposition: attachment; filename="pdf.pdf"');
print $pdfData;

My code of client side is

$.ajax({
     type:"GET",
     url:"/path",
     data:"param1=" + par1+"&param2="+ par2+ "&param3="+par3,
     success:function(msg){
               //alert(msg);
               //here needs to show that pdf but don't know how 
               document.write(msg);
     },
     fail:function(){
                alert('Error with pdf');                    
     }
  });

So when a user click on a link to get his bill i send AJAX call and get that pdf using SOAP WebService. The problem is that i can preview it or download it if i write /path in my browser, but don't know how to do it inside Javascript. What am i doing wrong?

KuKeC
  • 4,392
  • 5
  • 31
  • 60

1 Answers1

2

Well, you're sending a GET request, so you can simply do this:

window.location = "/path?" + "param1=" + par1+ "&param2=" + par2 + "&param3=" + par3;

You might also want to check this answer.

Community
  • 1
  • 1
Alexander Mikhalchenko
  • 4,525
  • 3
  • 32
  • 56
  • Thanks, sometimes simplest solutions are the best. I have put that my pdf downloads so with this line it automatically gets downloaded. The reason for that is that i don't want to show user /path?params for maybe get some other bills which are not theirs. Thanks for your answer +1. – KuKeC Dec 15 '15 at 12:49
  • @KuKeC since you generate the bill on the fly (i.e. don't store it as a file on your server), there's no need to worry about users downloading wrong file - you check the user permissions in the php script, don't you? ;) – Alexander Mikhalchenko Dec 15 '15 at 13:24