Reputation: 4408
I would like to send a lot of data through ajax request to my server which will generate pdf
or jpg
format according to that data.
Now i have done all that, my issue is to how output that generated pdf/jpg
back to the user trough ajax? I guess i might be able to use json
for that, but im not really sure how, and i think there would be a lot issues with pdf
.
Also if some one gonna suggest using form
with hidden
inputs that will not work since i have really big multidimensional array
with lot's of data and it would simply take to much effort to make it work.
By the way, i am using jquery
, but anything else is acceptable as long as it does the job done without making me to rewrite half of my script.
Upvotes: 0
Views: 671
Reputation: 11985
To display a JPG
AJAX: You can return the data hex encoded (be sure to set the content type appropriately: header('Content-type: image/jpeg')
). Then you just inject an <img/>
element into the DOM and set it's src
attribute to the returned Data URI.
HTML: Also, you could inject the <img/>
's with a normal src
URL to some location on your server.
For PDF
It's a little more tricky. Some browsers display PDF's natively (Chrome/Firefox), others rely on optional third-party plugins. You can detect these plugins, but can't control whether the PDF is displayed in a window/frame
or is downloaded.
If you choose to display, you can create a new window/tab to display it or display it in an iframe dynamically.
Upvotes: 1