tags:

views:

27

answers:

1

I need: 1) Get data from server by button click. (can ajax) 2) Execute some js depending on the received data. 3) Show standard "File save as" dialog.
It must work in IE7/IE8/FF.

Thanks! And sorry for my crooked english =)

+1  A: 

You can call a PHP file using ajax, which looks like this:

header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($fileContent));
header("Content-Disposition: attachment; filename=\"".$fileName."\"");
echo $fileContent;

This will display the "save as" dialog box in all browsers.

JochenJung
And how i can execute java script before "save as" dialog ?
Glum
Execute it in your main JS-script and pass it as a parameter to the PHP file.
JochenJung
But I need execute script after receiving data but before "save as" dialog"
Glum
`filename=` is not a valid header. You probably mean `Content-Disposition: attachment; filename="..."`. The `Content-Transfer-Encoding` is also superfluous, and none of the headers should contain a trailing `;`.
bobince
Thanks for the hints. I corrected my answer accordingly. +1
JochenJung