user974896
user974896

Reputation: 1813

Automatic download from jQuery POST request

I have a jQuery click event that makes a POST request to a PHP script that generates an XLS file. The PHP script returns the appropriate headers. When manually setting post variables and requesting RAW I see everything returns properly. I can even see this in firebug's console. The automatic "Save or Open" download box is not coming up however. I can not simply do:

window.location = ./path/to/generator.php

since the XLS returned is dependent on the POST variables passed. How can I achieve similar functionality.

Upvotes: 1

Views: 206

Answers (1)

Simon Edström
Simon Edström

Reputation: 6619

I don't think you can actully. Try to send the POST to your PHP script, generate the file and save it in the cache. Response to the client with the cache ID, and redirect the client so it makes a new GET request. Send the cached file with the modified headers.

Upvotes: 2

Related Questions