0

So I want to submit a form, wait for the response to come, and then fire off a trigger. The issue is the response to the form is a filecontentresult, so I cannot use AJAX. Essentially, I have a popup and then I wait for the form to submit and then close it, so that the user cannot edit the webpage mid-way through submission.

so like this:

$.Popup("Message");
var form = $('<form/>', {
    action: url,
    method: 'POST',
    style: 'display:none;'

});

... Adding stuff to form here ...

form.submit();
$.Popup.close();

The issue is that the popup closes before the form response comes through.

To clarify: the result is NOT a redirect, it is a FILECONTENT result. This does not cause the page to reload.

Thanks in advance!

tereško
  • 56,151
  • 24
  • 92
  • 147
Taugenichts
  • 1,149
  • 11
  • 18
  • `.submit()` will force a page load, so there's no need to close the popup. Just remove it :) – Reinstate Monica Cellio Apr 03 '14 at 19:58
  • The pop-up does not close. It's more of an overlay to the page than a pop-up I suppose. (a spinning circle type deal; I just replaced the name with pop-up for anonymity) – Taugenichts Apr 03 '14 at 19:59
  • `.submit()` doesn't do a submit in the background though - it opens the url in the action attribute, so there'll be no popup/overlay when that happens unless you open it again. – Reinstate Monica Cellio Apr 03 '14 at 20:00
  • You can say that as many times as you'd like, but it's not going to get rid of the pop up lol. I do not reopen it. The issue is it doesn't go away when the form finishes submitting. – Taugenichts Apr 03 '14 at 20:01
  • You're not submitting the form then, or not giving us the whole story. Submitting a form causes a page load. – Reinstate Monica Cellio Apr 03 '14 at 20:05
  • I said it was a filecontentresult, not a redirect. I'm not submitting the document, I'm submitting a form I made in javascript and appended to the document. That should be apparent from the code I gave. – Taugenichts Apr 03 '14 at 20:08
  • That's not relevant. The relevant fact is that you're not embedding it in your page, which is the only reason it doesn't submit like a regular form. Now that that has become apparent you may get some relevant help. Good luck :) – Reinstate Monica Cellio Apr 03 '14 at 20:10
  • Nope, the solution there was to use AJAX. I cannot use AJAX because I'm returning a file, rather than just a JSON object. I've tried this... =/ – Taugenichts Apr 03 '14 at 20:22
  • The one i linked doesn't use ajax, :) – Kevin B Apr 03 '14 at 20:23
  • Did not see your's before I posted. My bad. I'll look into it. – Taugenichts Apr 03 '14 at 20:29
  • set the target of a form an hidden iframe and on iframe load close the popup – albanx Apr 15 '15 at 09:00

1 Answers1

0

I would just restruchure your submit or popover to do the other command on callback. ie.

$('a.downloadLink').click(function() {
  $.Popup.close();
});
acrawly
  • 423
  • 1
  • 6
  • 10
  • The issue with doing this, is that once the form is submitted, it doesn't wait for the response. It just submits the form and it's done. All the logic in the background where it renders the files still goes on, but the popup has closed. – Taugenichts Apr 03 '14 at 20:16
  • Not sure I fully understand (sorry!) so you have a popover with a file upload, that you want them to upload then you want to parse the data, give a response and wait for X to happen then close the popover AND submit the form? – acrawly Apr 03 '14 at 20:18
  • ok, so here's how it goes, I put up a pop up, I submit the form with the data to download a file, the file renders in the background, and then gets sent back to the webpage (via a file content result) then I want to popup to close. popup -> render -> download -> close popup (would be the easiest way to describe it) – Taugenichts Apr 03 '14 at 20:19
  • Would something like this make sense? After the popup is called, render the data inside the callback, then attach an event listener to the download link and close the popover then? I've added code above. – acrawly Apr 03 '14 at 20:22
  • I'm looking into it. Thanks. – Taugenichts Apr 03 '14 at 20:41