How does javascript register a callback to run when the server has completed processing a form? This is my particular setup:
<form
id="savePlaylistForm"
name="savePlaylistForm"
target="savePlaylistIFrame"
method="post"
action="<?=base_url()?>index.php/savePlaylist">
<input
type="hidden"
id="savePlaylistEntire"
name="savePlaylistEntire" />
</form>
<iframe
id="savePlaylistIFrame"
name="savePlaylistIFrame"
style="display: none">
</iframe>
I've tried the following to no avail:
onSubmit
Attaching onSubmit to the form is not the right event because onSubmit happens when the client tries to submit. The server hasn't even been contacted yet.
onLoad
I attached an onLoad to the target iFrame. It doesn't get fired in my case. My server script sets headers to emulate an m3u playlist file. IFrames only fire onLoad when a normal HTML page is loaded, not when a file save dialog pops up. Even if I were to load a plain HTML page in the iFrame, onLoad would only fire the first time the user submits the form. Subsequent submissions won't fire onLoad.
XMLHttpRequest
object (xhr
) to submit the data, you should be able to bind an event to theonreadystatechange
event. In there you should be able to interrogate the returned headers usingxhr.getResponseHeader('Content-Type')
or whatever. Might not even need to interrogate if theonreadystatechange
event fires and thereadyState == 4
. – ggutenberg