0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

And how i can execute java script before "save as" dialog ?
Execute it in your main JS-script and pass it as a parameter to the PHP file.
But I need execute script after receiving data but before "save as" dialog"
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 ;.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.