download with dialog box with AJAX?

P

Petra Meier

Hi,

on mouseclick I want to create a HTML on the server via PHP this file I
want to send to the client in a way that the user is prompted with a
"save as" dialog box.
I know how to do it "normally" (I use 'octet-stream') .. now I want to
do that with AJAX and do not succeed (the file is sent but no dialog
box).. what do I have to account for in AJAX case or is this not
possible in AJAX?

thx

pm
 
V

VK

Petra said:
Hi,

on mouseclick I want to create a HTML on the server via PHP this file I
want to send to the client in a way that the user is prompted with a
"save as" dialog box.
I know how to do it "normally" (I use 'octet-stream') .. now I want to
do that with AJAX and do not succeed (the file is sent but no dialog
box).. what do I have to account for in AJAX case or is this not
possible in AJAX?

In AJAX there is no file as such: there is responseText or responseXML
string you would need to write to file (which has to be created then).
So the question is if JavaScript can get an access to the local file
system. Within the standard security environment it can't.
 
Y

Yanick

Petra Meier a écrit :
Hi,

on mouseclick I want to create a HTML on the server via PHP this file I
want to send to the client in a way that the user is prompted with a
"save as" dialog box.
I know how to do it "normally" (I use 'octet-stream') .. now I want to
do that with AJAX and do not succeed (the file is sent but no dialog
box).. what do I have to account for in AJAX case or is this not
possible in AJAX?

thx

pm

Well, no it can't. Downloading a file from the server requires some
headers to be set, unfortunatly (or fortunatly), Javascript cannot
control headers sent by the server ; downloading a file is strictly a
browser behavior. But if you mean that you want your users to be able
to click a link and download a file without the entire page to be
refreshed, then you must use a hidden iframe (well, not hidden, but
with size of 0 by 0) and foreward the url into that iframe. Since the
parent browser will be the same window as your page's, a dialog box
will popup asking the user to save the file sent to the iframe.


Hope this helps.

-Yanick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top