Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > AJAX & PHP - generate report & force download?

Reply
Thread Tools

AJAX & PHP - generate report & force download?

 
 
k.mitz@worldnet.att.net
Guest
Posts: n/a
 
      09-10-2005
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>

 
Reply With Quote
 
 
 
 
k.mitz@worldnet.att.net
Guest
Posts: n/a
 
      09-11-2005
Well Dr., I'm using the PEAR HTTP_Download class, and the content type
is set as 'application-pdf', as shown below. But, what the heck, I
tried octet-stream. Same results.

I've also tried the location.href = 'test.pdf' code, which works fine
for a static file, but I need to generate the report first (it changes
now and again).

Obviously, I can get it to work if I load the page with the code shown
below, but I'd like to keep the user on the original page, which in my
limited understanding is what AJAX seems to be about...

//PHP code

include('HTTP/Download.php');
$dl = &new HTTP_Download();
$dl->setFile('/tmp/test.pdf');
$dl->setContentDisposition('inline', 'test.pdf');
$dl->setContentType('application/x-pdf');
$dl->send();

PS I've also set the content disposition to attachment.

 
Reply With Quote
 
 
 
 
k.mitz@worldnet.att.net
Guest
Posts: n/a
 
      09-11-2005
Thanks for the prescription, Dr. I tried it, but the result was the
same.

//PHP code

include('HTTP/Download.php');
$dl = &new HTTP_Download();
$dl->setFile('/tmp/test.pdf');
$dl->setContentDisposition('attachment', 'test.pdf');
$dl->setContentType('application/x-pdf');
$dl->send();

Here's what actually ended up working...I changed the first function to
this:

//Javascript

function searchSales(rptID)
{
var url = 'http://192.168.1.128/sendReport.php?rptID=' + rptID;
location.href = url;
}

I'm sure I tried that before...Oh, well.

Thanks for your post.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Training Institute In Delhi, Live Projects on PHP. Short TermPHP Courses, PHP Scripts, PHP Training with Live Projects. Rajive Narain Java 0 09-18-2009 10:47 AM
Nike air force one, air force 1, air force one low cut, air force one salewholeta@163.com Digital Photography 3 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57