All,

I hope I can explain this right. We have a web application we are working (ASP) and we want the ability to create PDFs for the user. These PDFs can take up to 2 or 3 mins to create and we do not want to tie up the user while the PDF is getting created (the user clicks on a button when they want a PDF of a report)

On another forum, one of the members suggested I use Ajax to create the PDF asynchronously so the user can navigate through the web application while the PDF is getting created. I put some Ajax in my code and I am still have problems. The PDF is getting created correctly but if the user tries to navigate away from the page (we have a menu system on the page that is a series of <a href=""></a>) via our menuing system, the page does not navigate until the PDF is done being created. I can go on the URL line and enter the page I want to navigate to w/o a problem but this is not a valid solution for us.

Does anyone know why this is happening? Or is this a limitatioin of Ajax?

Thx
jonpfl

Recommended Answers

All 10 Replies

Javascript(or ajax) stops processing once the user navigates away from the page, always. The backend script will continue on the server but the javascript that outputs the header to the user once the ajax responds back will stop. I suggest openning it in a new window, and using some type of processing.gif image to alert the user that that window is processing the pdf and should be left alone.

Deleted

Javascript(or ajax) stops processing once the user navigates away from the page, always. The backend script will continue on the server but the javascript that outputs the header to the user once the ajax responds back will stop. I suggest openning it in a new window, and using some type of processing.gif image to alert the user that that window is processing the pdf and should be left alone.

I don't mind if the user navigates away from the page. I want to give the user the option to kick off the PDF process and forget about it (and contact them via email when it is done).

Is this possible? It seems that while the PDF is being created, I cannot navigate to other parts of the web app using buttons or links. If I want to actually type in the URL in the navigation bar, it seems to work fine. I was hoping there was a way for the user to use our menuing system (buttons and links) to continue on using our website and we would email them the PDF when it was completed.

Thx
jonpfl

I don't mind if the user navigates away from the page. I want to give the user the option to kick off the PDF process and forget about it (and contact them via email when it is done).

Is this possible? It seems that while the PDF is being created, I cannot navigate to other parts of the web app using buttons or links. If I want to actually type in the URL in the navigation bar, it seems to work fine. I was hoping there was a way for the user to use our menuing system (buttons and links) to continue on using our website and we would email them the PDF when it was completed.

Thx
jonpfl

Sure, the server will continue to run even after the user navigates away from the page, at least I know that php does. And just have it drop the file into a directory, then I would set up a cron to send the files out and delete them regularly.

You will need some sort of a session level variable on your server - that is unique to the user. This could be something like pdf_ready (true|false)

You will probably have to trouble at all firing off the AJAX request to start creating the .pdf - You can then allow the user to navigate around. The user will need some sort of a visual cue that their PDF is ready - so you could maintain a small status bar for their "job" - and when the server finishes creating the PDF - it just needs access to the users session level variable. When pdf_ready is true - the UI gets updated and the user can click to claim their freshly minted PDF file. You'll want to track that as well - for cleanup purposes.

ASP has some pretty simple facilities if i remembet - much like JSP and servlets to maintain a user session level variable.

In general you will have to watch out for memory issues as well as a way of cleaning up the PDF files themselves on the server. Session can become bloated if you carry around too much user information in them - and slow down your server - so as a rule you need to use session level data sparingly. Yours is a good case for it though.

Sure, the server will continue to run even after the user navigates away from the page, at least I know that php does. And just have it drop the file into a directory, then I would set up a cron to send the files out and delete them regularly.

My problem is that I am not seeing this behavior. When I try to navigate to another page (by using a button or href on the page), the request does not return from the server until the PDF creation processing is done (I verify this by watch a directory where the PDF gets saved to).

Thx
jonpfl

When I try to navigate to another page (by using a button or href on the page), the request does not return from the server until the PDF creation processing is done

So what you are saying is that the server will not respond to a redirect request until the PDF is complete?

So what you are saying is that the server will not respond to a redirect request until the PDF is complete?

Yup

Do you know if there is a way around this problem? Any child window the parent spawns seems to be linked. Is there a way for the parent to "release" the child so it is like a truly seperate IE window?

Thx
jonpfl

Actually I was thinking of another solution.

I know when I issue a windows.open() command in javascript, it is part of the same process.

Does anyone know a way to open a new window in a different process? I know that I open up a new window and start the PDF process, I can open up another window and continue to navigate around.

Any thoughts?
jonpfl

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.