0

I am able to get the output of a pdf using fpdf, the problem is that i am not to generate it if the call the function through jquery... rather the pdf is display in firebug?How to solve this issue

output display in firebug

%PDF-1.3
3 0 obj
<</Type /Page
/Parent 1 0 R
/Resources 2 0 R
/Contents 4 0 R>>
endobj
4 0 obj
<</Filter /FlateDecode /Length 582>>
stream
x���Ms�0���{LU���͞&�v�L�p��b��N��`Zc���k,ij��Bgh��b���{�|�����șP`�f�B���sS��C���*+�[H��K�ŁO��מ�����M:<�3�jt�:Z��1,�`�ˤc
�Ҁ��        ��0���~��^��U�  �;�q�_6y
y�� ��+Q�6��e/���C%�ً+�!q5+�Sf

jquery:

        $.post(url+"/create_pdf",js,function(data){

        },"json");
dude
  • 4,532
  • 8
  • 33
  • 51
  • You can't use ajax to let the browser show the "download" file dialog. But there's [a workaround using a hidden – vstm Jun 21 '12 at 11:49
  • can u tell me the proper changes what i have to do? – dude Jun 21 '12 at 11:50

1 Answers1

1

Instread of $.post() (which will run the PDF gnerator and return contents to AJAX), you should redirect the user to the url in the browser: i.e. use

window.location.href=url+"registration/create_member?" + $.param(js);

You will need to convert your PDF generating function to accept $_GET, not $_POST

Alternatively, generate the pdf file as you are doing but store on server (temporarily) and pass the url back through ajax, Then ajax redirects the user to that temporary file location through windows.location.href instead.

Robbie
  • 17,605
  • 4
  • 35
  • 72