0

I've got a button (link to controler/action) which after clicking calls action validating and generating pdf from php. This function validates i.e. if pdf should generate for this user and if there will be any errors it would not generate certificate but show those errors (of course, if there's no error it will generate certificate and download the file).

I need to do this without reloading the page. And that brings a problem. When I call this function through ajax it gives me the answer with json about any occuring errors, but if there's error it does not generate pdf but ajax gives me PDF as hashed text. I would like to force it to generate pdf and download it to pc.

1 Answer 1

2

You can't make the client download the file through an ajax request, because with an ajax call you are generating the PDF server-side with PHP and returning his content to the caller script ( in fact you retrive the pdf hashed text)

What you could do is generate the PDF in the ajax call, save the file somewhere, and then return a response from the ajax call. If the response is 'negative' you could show the errors without reloading the page. If the response is positive you could redirect from javascript (non via ajax) to a PHP script serving the just-created PDF

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.