I attached console screen shots, for image and doc file, a response from server, but when save file, file corrupted. This seems to work for me in the latest Firefox. You can have the browser return your Blob object directly rather than having to construct it. Doing that with jQuery's ajax code is a bit of a pain though as they do not expose native object or it's.
I would suggest not hiding your link to download the file, that way the user can manually click it should the automatic. I suspect this is what is causing your corruption issue as the binary data you're returning will get encoded as text. Look over my example above, make sure you're doing everything correctly. Post your updated code if you continue to have issues.
You may just be missing a step or have some code in the wrong place. Use JavaScript's window. That way the browser doesn't try to redirect the user because it will recognize the download link and not actually open a new tab.
Dear kicken , I implimented your code, i am getting a issue, please can you advice. Dear kicken ,. I used following method. You shouldn't be using print there.
The readfile function outputs the contents directly rather than returning it. Having the print may be introducing extra data that corrupts the file. You mentioned earlier something about it having to be an ajax request, but is that because that's all the server allows or do you just think that because of your single-page app behavior?
If the server only allows an ajax request, i'd look into changing the server configuration so your direct link works as it'd be much simpler and more compatible. Thanks for your concern. I just found the issue, issue is with my code. But ajax check is important for application i cannot remove.
Solved by adding ajax. You can post now and register later. Posted 5-Oct am Member Updated 9-Oct am Kornfeld Eliyahu Peter. Add a Solution. Richard MacCutchan 6-Oct am. And you think that we can guess what message and where it occurs? You have updated the question, but we still have no idea what message or where it occurs. Accept Solution Reject Solution. Posted 9-Oct am Richard Deeming. Member Oct pm.
Add your solution here. OK Paste as. Treat my content as plain text, not as HTML. Existing Members Sign in to your account. This email is in use. Do you need your password? Submit your solution! When answering a question please: Read the question carefully. I am using PHPExcel to read an excel template, populate the data, and ask the user to download the file. Using chrome developer tools, I can see from the Network tab that the ajax call was successfully completed and a bunch of random characters is seen in the response data.
I'm assuming that is the excel object. Does anyone know how I can achieve the download excel feature using ajax? I don't want to refresh the page. When the user clicks on the "export" button, there should be an ajax call to the php file and prompt the user to download. I looked around and put some pieces together, hope it can help someone:. Not everything should be done with AJAX. Sometimes plain old HTML is more suitable for a job.
I guess your button has a tag? Why won't you do something like this. It's there to make sure your page is not reloaded. I don't think you can download anything by ajax call.
Instead of you can generate and save the excel in server temporary and show the download link to the user.
I added a hidden iframe in the page. When the ajax call returns, it returns the url of the created data. I used javascript to redirect the iframe to that url which automatically triggers the download action.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more.
0コメント