1352
Views
6
Comments
Solved
Link: problems with Submit and Ajax submit
Question

Hi all !


I have a text link with a Submit method: in my screen action I have a SQL insert, a refresh data, an Ajax refresh and a download of a file.


At the moment the download is working, but the ajax refresh is not.


If I change the method to "Ajax submit" I have the ajax refresh working but the download of the file is not ... showing me the error message: "Server cannot set content type after HTTP headers have been sent".


I there the possibility to let all my actions working ??

2020-02-28 09-46-54
Eduardo Jauch
Solution

Hello Luca,

Besides the component mentioned by Sam (that has a very interesting approach), there are other possibilities. One is to use a small trick you can do, that may or may not be sutable for you.

1. Create a link, give it a name (like DownloadLink), method submit, that will execute the download. Bind it to a screen action and do the download from that screen action. Hidden the link using css (display:none), or putting it inside a container with the Display property set to No.

2. The original button, change the method to Ajax Submit. Inside it, instead of finishing with the download (that will be done by the hidden link). Before the End Point, add a RunJavaScript (from HTTPRequestHandler) with the following code:

"$('#" + DownloadLink.Id + "').click();"

What will happen is that the visible button will execute everything that you need and at the end, it will send to the browser a small JavaScript to click the hidden link that will actually do the download.

Hope this helps.

Cheers.

2024-02-27 12-57-22
Sam Rijkers

Hi Luca,

As you noticed, you cannot use ajax refresh and upload/download together. You should try to find a workaround. It is hard to suggest one, since I don't know any details of what you want to accomplish. (You didn't get a warning, which is already suggested in this idea).
RefreshAfterDownload forge component might be of use in your case, but as I said, I don't know exactly what you try to accomplish. So you could try to use this component, or tell us what you want to do.

Sam

2020-02-28 09-46-54
Eduardo Jauch
Solution

Hello Luca,

Besides the component mentioned by Sam (that has a very interesting approach), there are other possibilities. One is to use a small trick you can do, that may or may not be sutable for you.

1. Create a link, give it a name (like DownloadLink), method submit, that will execute the download. Bind it to a screen action and do the download from that screen action. Hidden the link using css (display:none), or putting it inside a container with the Display property set to No.

2. The original button, change the method to Ajax Submit. Inside it, instead of finishing with the download (that will be done by the hidden link). Before the End Point, add a RunJavaScript (from HTTPRequestHandler) with the following code:

"$('#" + DownloadLink.Id + "').click();"

What will happen is that the visible button will execute everything that you need and at the end, it will send to the browser a small JavaScript to click the hidden link that will actually do the download.

Hope this helps.

Cheers.

2020-10-02 21-47-41
Samuel Nunes Marques

Hi Luca De Mori,

Another solution for your problem is create a new web screen and download the file in the preparation of that new screen.
At the end of your link(Ajax Submit) logic, instead of an "End", just use a "Destination" to the new screen that you created before.

Samuel

2020-02-28 09-46-54
Eduardo Jauch

Samuel M. wrote:

Hi Luca De Mori,

Another solution for your problem is create a new web screen and download the file in the preparation of that new screen.
At the end of your link(Ajax Submit) logic, instead of an "End", just use a "Destination" to the new screen that you created before.

Samuel

It needs a second screen, but it is a really nice solution, Samuel :)


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Also, in addition to what Eduardo said, I personally prefer to use the WidgetClick() Action from RichWidgets instead of adding nasty JavaScript to the button.

2019-11-26 09-13-57
Luca De Mori

thanks for all the solutions ...


I'll experiment to find the best for me !

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.