I have got a problem with getting excel file and opening download window in the browser after getting a response (in success ajax method) with that file. I have got appropriate Content-Type and Content-Disposition headers, I tried using Blob in js and I couldn't achieve what I want - simple file downloading.
I accomplished few versions of my ajax, one of them is below. I developed ajax which returns excel file which I couldn't open properly because it's corrupted (despite .xlsx extension).
I tried using "xhr.response" instead of "data" from success method arguments but it doesn't work too. I checked Response Headers in Developer Tools in Chrome and they are set properly.
The important thing - all the excel workbooks created on the server side is correct because it worked in the previous version when data was sent in URL, not in ajax post.
We were having absolutely the same trouble recently. For us it started to work when we add responseType: 'arraybuffer' to the ajax parameters. And it's better to use lib instead of manual clicking on the link because this tool revokes memory as well.
As you can see, I'm trying to get around the async issue by calling the function recursively when the request comes back with data, meaning that it has to keep running. When I place a console.log() just before the return, I can see that it is compiling the results as I need it to. However, the return from calling readFileRow() is coming back before the process finishes and consists of the response from the very first ajax query, having apparently not been run through the .done() function. I've tried removing the return in front of the ajax call, but this only causes an exception, since the return is no longer thenable and thus doesn't have a .done() function.
This one seems the closest to what I'm after: asp-net-mvc-downloading-excel - but I'm not sure I understand the response, and it is a couple years old now. I also came across another article (can't find it anymore) about using an iframe to handle the file download, but I'm not sure how to get this working with MVC.
My 2 cents - you don't need to store the excel as a physical file on the server - instead, store it in the (Session) Cache. Use a uniquely generated name for your Cache variable (that stores that excel file) - this will be the return of your (initial) ajax call. This way you don't have to deal with file access issues, managing (deleting) the files when not needed, etc. and, having the file in the Cache, is faster to retrieve it.
I am working on an application where I can have a grid with X items, and each item has a print button. Clicking this print button allows me to call an ajax function which passes the ID of the grid item to a controller. I retrieve the relevant data based on that ID and then download it in an excel file. (The retrieving of the specific item is not yet done)
I have the following function that is pulling data from a database. The ajax call is working correctly. How can I send the tab delimited data in my success function to the user? Setting the contect type to "application/vnd.ms-excel" didn't work. The alert on success shows the correctly formatted data.
Question: I would like to use jquery ajax to achieve the same result since I have more flexibility and can pass objects into the action, rather than append the required parameters to the query string. Is this possible? If so, what would ajax return in this case?
could the excel button just populate a form field with the variables and then submit it, without ajax? So long as the content type is set to be application/ms-excel, it would prompt the user to open or save the file (or whatever the browser's default behavior seems to be).
Now, the server should reply with a 200 status code response to the preflight request, regardless of the authentication.
Step II,
Since this is a CORS request, the above change is not enough to make the XMLHttpRequest call go through.
With the changes in Step I, the Chrome browser console shows a different error:
(index):1 XMLHttpRequest cannot load http://***/_vti_bin/listdata.svc...
Request header field crossDomain is not allowed by Access-Control-Allow-Headers in preflight response.
Make the following changes to the web.config for the SharePoint Web Application, to add some custom headers required to make a CORS request:
Sample code block in Web.Config. You will need to update the value of Access-Control-Allow-Origin to point to your remote ajax application. In the below XML, where it has you would put the host of your remote application that is calling to SharePoint (e.g. )-
----
After a lot of research i found this site and the essence of its statment is that jquery ajax does not support receiving binary data, but provides a solution for implementing plain xhr request which support blob transfer.The Site: -binary-files-using-jquery-ajax/
When I open generate_excel.php directly from the browser, the result file is downloaded.But if I make an ajax call to the generate_excel.php, I don't get the download prompt. 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.
Hi, It seems one of my existing excel vba marco stopped working when I upgraded from WINDOWS7 to WINDOWS10. Can someone help to locate the issue and provide guidance to fix it.
I did tried by adding Microsoft XML 3.0 or 6.0 reference but in both attempt I still get a blank xmlhttp.responseText.