2009/3/2 Alex Mcauley <[email protected]>: > > The way i do it in my custom CRM (for editing and downloading invoices > (Mainly PDF's)) is to submit a form to a hidden Iframe which automatically > calls the browser to open or download the document ... > > This is streamed in a similar way to your streaming that you mentioned > earlier .. > > what i would do in your case is when all the headers are sent to the browser > i would echo some javascript to call the parent telling it that it is > finished ... > > Example in your ajax request set evalScripts to 'true' and send some JS back > to the server ... if this is unsecure for you then just echo out some HTML > that you can query .. > > The only downside of echoing out HTML is you may have to periodically check > the DOM to see if its there or not ... at least with echoing javascript it > will do something when responded .. > > Now .. the downside with PHP is ... quite often javascript is interpretted > before a [PHP] script has finished executing (i allways wrap my scripts > with EG. if($sql) {echo("<script>alert('Finished');</script>");} else { > ... } (this one scratched my head a few times windering why Ajax Requests > were reposnding before a database change had ben done !!! ... > > If its high load server then you can put a sleep call in php or buffer the > output slightly to compensate for it .. > > I dont know why php does this and it may be the same in other serverside > languages ... most of the time the script executes before the javascript is > interpreted so it doesnt matter but on high load servers thismight not > allways be the case > > HTH > > Alex > > > > > ----- Original Message ----- > From: "Richard Quadling" <[email protected]> > To: <[email protected]> > Sent: Monday, March 02, 2009 2:02 PM > Subject: [Proto-Scripty] Re: User triggered download with no page refresh. > > > > 2009/3/2 Richard Quadling <[email protected]>: >> 2009/3/2 zero <[email protected]>: >>> >>> On page that iframe load u can put code: >>> <script type="text/javascript"> >>> parent.name_of_some_js_function(); >>> </script> >>> Works for me in all browsers. >>> >>> On 2 Mar, 14:21, Richard Quadling <[email protected]> wrote: >>>> Hi. >>>> >>>> I'm currently using an iframe to act as a report downloader. >>>> >>>> The user enters some criteria which is generated dynamically as they >>>> change options. They then click a document button (PDF, XLS, DOC) and >>>> this is sent to the server for validation. The result is a key for the >>>> Crystal Reports. The JS code generates an iframe and passes the key as >>>> part of the URL. As the key is a hash, and has to be part of the >>>> user's session, security is quite high. Guessing keys is useless >>>> unless there is corresponding data already submitted for the key. >>>> >>>> On screen, I dim the form for ajax requests and fade in a spinner. >>>> >>>> So far so good. >>>> >>>> My problem is that once I've created the iframe I've no way of knowing >>>> about the state of the iframe - has it loaded and presented the user >>>> with the appropriate download box. >>>> >>>> Are there any events I can observe with regard to an iframe (ie7, FF, >>>> Chrome - intranet only and so can be limited in support). >>>> >>>> I suppose as a side question, how do I find what events are observable >>>> for any element? Is there a way? Or is it just a case of RTF HTML/JS M >>>> >>>> Regards, >>>> >>>> Richard Quadling. >>>> >>>> -- >>>> ----- >>>> Richard Quadling >>>> Zend Certified Engineer >>>> :http://zend.com/zce.php?c=ZEND002498&r=213474731 >>>> "Standing on the shoulders of some very clever giants!" >>> >> >>> >> >> Hmm.. >> >> Currently, the iframe has no HTML/CSS/JS content as the server simply >> supplies a download which causes the browser to ask to save. I'm using >> PHP and here is the key part. >> >> // Generate file and then supply headers along with the data. >> header("{$_SERVER['SERVER_PROTOCOL']} 200 OK", True, 200); >> header('Content-Description: File Transfer'); >> header("Content-Type: >> {$_SESSION['Reports'][$_GET['Hash']]['ExportInfo']['Mime']}"); >> header('Content-Disposition: attachment; filename="' . >> $_SESSION['Reports'][$_GET['Hash']]['Report']['ExternalName'] . '.' . >> $_SESSION['Reports'][$_GET['Hash']]['ExportInfo']['Extension'] . '"'); >> header('Content-Transfer-Encoding: binary'); >> header('Expires: 0'); >> header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); >> header('Pragma: public'); >> header('Content-Length: ' . filesize($s_ExportedReport)); >> readfile($s_ExportedReport); >> unlink($s_ExportedReport); >> >> So, I can't add HTML/CSS/JS to the frame AND have the download happen. >> >> I found I can observe the "load" event on the iframe, but only in >> FireFox. It seems that nothing is fired for IE/Chrome at all. Also >> tried dom:loaded - nothing in any of the browsers. >> >> I think the above code would need to be amended to do something like this >> ... >> >> Generate the report and save it with a unique name. >> Generate the iframe's HTML so that it includes the JS to tell the >> parent all is well and a location.refresh to point to a script to >> supply the newly generated file. >> >> Seems convoluted, but then again, downloading with no refresh SEEMS >> convoluted anyway. >> >> And as I'm typing this, Alex has just replied ... reading. >> >> Ah. Yes. If the iframe had content, then I could traverse it quite >> happily. >> >> Breaking the generation and the downloading seems to be the next obvious >> way. >> >> Any other POVs? >> >> Richard. >> >> >> -- >> ----- >> Richard Quadling >> Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 >> "Standing on the shoulders of some very clever giants!" >> > > Or duh ... > > http://particletree.com/notebook/ajax-file-download-or-not/ > > Is this right? > > A straight form with a download link (i.e. form's response will be > downloadable file?) Just triggered using JS? > > Hmm.. Of course that will work,but I still don't know when the form is > ready. > > So maybe a form event to know it has finished processing would be a > better/easier solution ... looking into it ... > > -- > ----- > Richard Quadling > Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!" > > > > > > >
It is amazing that just by asking the question out loud, the answer is obvious. Currently ... User enters data User submits data Server verifies data Server returns hash. Client generates iframe iframe calls generator Client activates controls and there is a delay whilst the file is generated. generator returns file. Solution ... User enters data User submits data Server verifies data If verified ok Generate file Return hash else Return error. Client generates iframe iframe calls downloader Downloader returns file and then cleans out session and file. Client activates controls via the onsuccess. All working fine. Thank you for listening. Regards, Richard. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
