in reply to Re^3: Can two separate responses be sent to the client's browser from Perl, such as via fork{}?
in thread Can two separate responses be sent to the client's browser from Perl, such as via fork{}?

Bliako,

I'd ++ that post more than once if the system allowed. You're very kind to provide code examples. Not having worked with JSON before, it may help me a lot. I've already been trying to work out how to do things via the information at the links provided earlier--so far have yet to get the download to initiate via AJAX. I know it must be possible somehow, but it seems the entire page almost needs to refresh to get the download http headers. I don't know. In any case, only when the entire page is submitted does it seem to work, whereas with AJAX the page is not refreshed, only updated in key parts.

Regarding the module you suggested, I was unaware of it, but have already got something working. From a quick glance at the description, though, I'm uncertain the module would help me. It says: "run_latex Runs the formatter (latex or pdflatex)." I'm not able to use pdflatex (I wish I could, as it allows for microjustification) because I'm needing compatibility with Asian-language scripts. For my use case, only XeLaTeX can do the job. Perhaps this is why I'm rolling my own script for this. Unfortunately, there are no microjustification capabilities for any TeX solution on these Asian scripts (Thai, Lao, Karen, Burmese, etc.). For that, people have to rent the very pricey (for this economy) Adobe InDesign--or else use Microsoft Word. Ugh!

Blessings,

~Polyglot~

  • Comment on Re^4: Can two separate responses be sent to the client's browser from Perl, such as via fork{}?

Replies are listed 'Best First'.
Re^5: Can two separate responses be sent to the client's browser from Perl, such as via fork{}?
by bliako (Abbot) on Oct 19, 2023 at 16:09 UTC

    Polyglot

    Regarding the first part, AJAX requests do not need refreshing the client page. Just concentrate on a test JS script where you click a button, it does AJAX request to server and presents some results in a div. Start from there. An important part of this is server-side: sending JSON back to client on an AJAX request. Once you get the individual components working all will fit together niecely. A WORD OF WARNING: obvioulsy the proper way is to hava the server queueing the client requests, processing them at its own time and notifying the clients (via an email, or via the client checking on the server, perhaps via a client-page timed-auto-refresh (see Re: Can two separate responses be sent to the client's browser from Perl, such as via fork{}?) etc.) when results are ready. This is what afoken and fletch are telling you.

    regarding LaTeX::Driver, it can run XeLaTeX too if you pass this parameter: 'format' => 'pdf(xelatex)' at construction time. There are options to specify the bin path.

    bw, bliako

      Regarding the first part, AJAX requests do not need refreshing the client page. Just concentrate on a test JS script where you click a button, it does AJAX request to server and presents some results in a div.

      Yes, this is exactly the problem. I'm familiar with AJAX, having learned several years ago to use it, rolling my own jQuery-free, no module, Javascript routines for this. The problem is that the http headers for a download are not compatible (as far as I can tell) with sending to a single div on a page--the download wants to BE the page. I have yet to get any download dialogue in the browser through an AJAX-initiated request. The only way I have ever gotten it to work is through standard form submission. I guess I'm just ignorant, because I am quite sure there must be a way to do it, but I can't wrap my mind around how to get the browser to download something sent back to a form element on the page via AJAX. If the others were instructing me in how to accomplish this, I haven't grasped it yet.

      Blessings,

      ~Polyglot~

        In the JS code in Re^3: Can two separate responses be sent to the client's browser from Perl, such as via fork{}?, this: var blob = new Blob([pdf], {type: "octet/stream"}); creates the blob with the specific download header to go into an <a> tag. You are right, this must be changed to var blob = new Blob([pdf], {type: "application/pdf"});. Then follow the rest on how to create the <a>. Please note: good practice is that when you are done with the download link you must tell the browser to release the blob data it created with window.URL.createObjectURL(blob) like:

        var objurl = window.URL.createObjectURL(blob); ... // i am done with this link now window.URL.revokeObjectURL(objurl);

        So, now your dynamic download link should contain the right headers.