K
k.mitz
Hi,
I have a PHP application that allows users to generate a .pdf report of
their database content. Normally, I've had to refresh a page to call
the script to generate the report, so there's a second or so when the
browser goes blank. I was wondering if it was possible to use AJAX to
call the script to generate the report, then begin the download without
refreshing the page (or in the case of I.E., leaving me with a blank
window that you have to back out of).
The following code 'works', in that it inserts the pdf code in the
textarea, but I'd want to force the browser to start a file download
without refreshing the page.
BTW, I'm using the Prototype 1.3.1 library.
<script>
function searchSales(rptID)
{
//generates the report
var url = 'http://192.168.1.128/sendReport.php';
var pars = 'rptID=' + rptID;
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onComplete: showResponse} );
}
function showResponse(originalRequest)
{
//put returned XML in the textarea
$('result').value = originalRequest.responseText;
}
</script>
<a href="#" onclick="javascript:searchSales('1034')">Click</a>
<textarea id=result cols=60 rows=10 ></textarea>
I have a PHP application that allows users to generate a .pdf report of
their database content. Normally, I've had to refresh a page to call
the script to generate the report, so there's a second or so when the
browser goes blank. I was wondering if it was possible to use AJAX to
call the script to generate the report, then begin the download without
refreshing the page (or in the case of I.E., leaving me with a blank
window that you have to back out of).
The following code 'works', in that it inserts the pdf code in the
textarea, but I'd want to force the browser to start a file download
without refreshing the page.
BTW, I'm using the Prototype 1.3.1 library.
<script>
function searchSales(rptID)
{
//generates the report
var url = 'http://192.168.1.128/sendReport.php';
var pars = 'rptID=' + rptID;
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onComplete: showResponse} );
}
function showResponse(originalRequest)
{
//put returned XML in the textarea
$('result').value = originalRequest.responseText;
}
</script>
<a href="#" onclick="javascript:searchSales('1034')">Click</a>
<textarea id=result cols=60 rows=10 ></textarea>