468,556 Members | 2,357 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,556 developers. It's quick & easy.

I have a problem to create and download excel file at a time

I has made two method ExcelCreat() which create excel file And ExcelDownload() which download that excel file.both work separate properly but not ata time. I make a builder.append("<"<a href='/RestSimulator/rest/userReport/download' onclick='javascript:ExcelCreate();'>Download</a>");
prblem is that when I click href(Download) then excel is not created show error 500 file not found but we again press that link then file download.it means first time excel does not genetare but second time generate HOW TO CALL ExcelCreat() method first
Jul 3 '14 #1
1 1549
rajujrk
107 100+
Hi,

You trying to call 2 Javascript functions one by one immediately. Both functions are calling the Web/App Server and doing server side functionality. Coming to your problem, first you are trying to call the Create ExcelCreate (Which is processing to create a new excel file), Note: its still in process from server side. Before ending this process, immediately ExcelDownload is start to execute and trying to download the file, but file not created yet. This way will not work out.

My Soultion 1: (use AJAX)

1. In server side Excel Creation method, set a session variable say "FILEPROCESS" and set the value as "false". Once file created set the "FILEPROCESS" to true.

2. Create a new server side service called StatusService, inside this services just write out the session "FILEPROCESS" value.

3. Create one global boolean variable blgFlg = false in your javascript

2. Inside ExcelCreate() - Call new Javascript method called getStatus() before calling the server side services

3. Inside the getStatus() function use Ajax to call the StatusService and set the response Text to blgFlg variable.

4. If blgFlg = false, then call setTimeout('getStatus()', 500);

5. If blgFlg = true, then call ExcelDownload()


My Soultion 2:

Instead of having 2 javascript function, use 1 javascript function and use 2 server side methods

If you have any clarifications, please continue to post ur reply

Thanks
Raju
Jul 3 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Martin | last post: by
27 posts views Thread by jeniffer | last post: by
15 posts views Thread by patf | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.